havenwood changed the topic of #ruby to: Ruby 3.3.6 (3.4.0-preview2) https://www.ruby-lang.org | Log https://libera.irclog.whitequark.org/ruby
eddof13 has joined #ruby
eddof13 has quit [Quit: eddof13]
naiithink has joined #ruby
TomyWork has quit [Quit: Leaving]
naiithink has quit [Quit: leaving]
naiithink has joined #ruby
cappy has quit [Quit: Leaving]
Sampersand has joined #ruby
eddof13 has joined #ruby
konsolebox has joined #ruby
eddof13 has quit [Client Quit]
Munto has quit [Ping timeout: 246 seconds]
brokkoli_origin has quit [Remote host closed the connection]
brokkoli_origin has joined #ruby
Munto has joined #ruby
naiithink has quit [Quit: leaving]
Sampersand has quit [Ping timeout: 256 seconds]
CRISPR has joined #ruby
CRISPR has quit [Ping timeout: 264 seconds]
CRISPR has joined #ruby
konsolebox has quit [Ping timeout: 240 seconds]
CRISPR has quit [Ping timeout: 272 seconds]
donofrio has joined #ruby
fercell has quit [Ping timeout: 244 seconds]
brokkoli_origin has quit [Ping timeout: 252 seconds]
brokkoli_origin has joined #ruby
dviola has quit [Quit: WeeChat 4.4.3]
konsolebox has joined #ruby
CRISPR has joined #ruby
donofrio has quit [Ping timeout: 265 seconds]
CRISPR has quit [Ping timeout: 252 seconds]
Sampersand has joined #ruby
donofrio has joined #ruby
donofrio has quit [Ping timeout: 276 seconds]
dviola has joined #ruby
Fridtjof has quit [Quit: ZNC - http://znc.in]
hwpplayer1 has joined #ruby
Zamyatin has joined #ruby
Fridtjof has joined #ruby
Zamyatin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Sampersand has quit [Ping timeout: 256 seconds]
hwpplayer1 has quit [Quit: I'll be back later]
grenierm has joined #ruby
eddof13 has joined #ruby
eddof13 has quit [Client Quit]
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
duderonomy has joined #ruby
sphex has quit [Ping timeout: 252 seconds]
sphex has joined #ruby
pages has quit [Ping timeout: 260 seconds]
pages has joined #ruby
konsolebox has quit [Read error: Connection reset by peer]
dannyAAM has quit [Ping timeout: 245 seconds]
dannyAAM has joined #ruby
dannyAAM has quit [Quit: Will be back soon!]
dannyAAM has joined #ruby
desnudopenguino has quit [Quit: desnudopenguino]
hwpplayer1 has joined #ruby
hwpplayer1 has quit [Remote host closed the connection]
chen has quit [Quit: No Ping reply in 180 seconds.]
chen has joined #ruby
grenierm has quit [Quit: Client closed]
lunarkitty8 has joined #ruby
lunarkitty8 is now known as lunarkitty
lunarkitty is now known as theonlymoonkitty
theonlymoonkitty is now known as lunarkitty
shiru has joined #ruby
Linux_Kerio has joined #ruby
shiru has quit [Quit: ERC 5.5.0.29.1 (IRC client for GNU Emacs 29.4)]
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Milos has quit [Read error: Connection reset by peer]
mx has joined #ruby
mx has left #ruby [Bye]
Milos has joined #ruby
Milos has quit [Read error: Connection reset by peer]
Milos has joined #ruby
jardsonto has joined #ruby
duderonomy has joined #ruby
brokkoli_origin has quit [Ping timeout: 252 seconds]
mretka has quit [Changing host]
mretka has joined #ruby
brokkoli_origin has joined #ruby
mange has quit [Quit: Zzz...]
konsolebox has joined #ruby
brokkoli_origin has quit [Remote host closed the connection]
dostoyevsky2 has quit [Ping timeout: 272 seconds]
qsx has quit [Ping timeout: 244 seconds]
brokkoli_origin has joined #ruby
qsx has joined #ruby
dostoyevsky2 has joined #ruby
konsolebox has quit [Ping timeout: 245 seconds]
user71 has joined #ruby
gorignak has quit [Quit: quit]
gorignak has joined #ruby
eddof13 has joined #ruby
gorignak has quit [Quit: quit]
gorignak has joined #ruby
Zamyatin has joined #ruby
Zamyatin has quit [Client Quit]
donofrio has joined #ruby
Zamyatin has joined #ruby
Zamyatin has quit [Client Quit]
TomyWork has joined #ruby
trillion_exabyte has quit [Ping timeout: 255 seconds]
trillion_exabyte has joined #ruby
Zamyatin has joined #ruby
donofrio_ has joined #ruby
Zamyatin has quit [Read error: Connection reset by peer]
konsolebox has joined #ruby
donofrio__ has joined #ruby
donofrio_ has quit [Ping timeout: 260 seconds]
rvalue- has joined #ruby
Pixi` has quit [Quit: Leaving]
rvalue has quit [Ping timeout: 264 seconds]
donofrio__ has quit [Ping timeout: 252 seconds]
rvalue- is now known as rvalue
konsolebox has quit [Ping timeout: 248 seconds]
hwpplayer1 has joined #ruby
<isene> string = "abcdaba123abcd" I need to split the string at index = 7, but first I need to disregard any "b" and "c", so that the string is split into "abcdaba123ab" and "cd". How?
cappy has joined #ruby
<isene> Would I have to count character by character to find the actual index (11), or is there a more elegant way?
hightower2 has joined #ruby
<hightower2> Hey I was delighted to see Hash#first which returns the first key/value pair. But there is no Hash#last. How can I retrieve the last pair inserted?
<adam12> hightower2: If it's not very large, I might just convert to array then call #last on that.
<adam12> hightower2: Alternatively, get last key, then lookup using that key? Not sure if it's any faster.
<hightower2> yeah that'd work, or since I only need the last value actually, I guess #values.last would do
<hightower2> (although I wanted to avoid the conversion of either keys of values to an array, but well...)
<adam12> I'm surprised #first works, tbh. Happy accident? It's not documented at all, and for a long time, Hash order wasn't consistent.
<adam12> (or guaranteed)
<hightower2> interesting. maybe it has some other effect... I ran it, and it seemed to return the first key/value I inserted as a [key, value]
<hightower2> s/ran it/just ran it/
<hightower2> but ok, values.last will do, thanks
<adam12> Alternative is to wrap the hash and keep record of the last entry...
admin1234 has joined #ruby
desnudopenguino has joined #ruby
hwpplayer1 has quit [Quit: sleep Zzzz]
donofrio has quit [Ping timeout: 252 seconds]
J_B has joined #ruby
<hightower2> yeah this is for troubleshooting, the direct approach will be quite fine
TomyWork has quit [Remote host closed the connection]
donofrio has joined #ruby
Pixi has joined #ruby
Sampersand has joined #ruby
admin1234 has quit [Ping timeout: 252 seconds]
Sampersand has quit [Quit: Client closed]
Linux_Kerio has quit [Ping timeout: 245 seconds]
polishdub has quit [Read error: Connection reset by peer]
<o0x1eef> Hash has been ordered for the longest time ? At least on MRI. But considered an "implementation detail".
admin1235 has joined #ruby
admin1235 has quit [Client Quit]
brw has quit [Remote host closed the connection]
brw has joined #ruby
polishdub has joined #ruby
donofrio has quit [Ping timeout: 276 seconds]
victori has quit [Quit: ZNC 1.9.1 - https://znc.in]
victori has joined #ruby
eddof13 has quit [Quit: eddof13]
donofrio has joined #ruby
<havenwood> o0x1eef: It's an implementation detail for Set but a documented behavior that's part of the spec for Hash.
user71 has quit [Quit: Leaving]
<adam12> o0x1eef: 1.8 were definitely unordered. I am not sure they ever came out to say they retained order until just recently.
donofrio has quit [Ping timeout: 255 seconds]
<adam12> havenwood: ah yes. thanks.
<havenwood> Matz was happy to have Hash be ordered in 1.9 and going forward but has reserved the right to make Set unordered.
<havenwood> Practically, I think we'd need to add an OrderedSet but it makes sense that Set might not _always_ be implemented internally as Hash keys.
<havenwood> I suspect a fair amount of stuff would break insidiously with unordered Set.
Sampersand has joined #ruby
<Sampersand> hey its the wood of havens
<havenwood> o/
Rounin has quit [Ping timeout: 244 seconds]
<havenwood> Sampersand: Whaddaya think on that ^ solution? Too lazy?
<isene> Damn. Could you explain 7 - 14? How does that work?
<Sampersand> lemmie se
<havenwood> isene: I use `.each_grapheme_cluster` instead of `.each_char` to be able to handle UTF-8 characters beyond ASCII as well as things like emoji.
<Sampersand> there's probably a shorter answer
<havenwood> the `.with_index` returns another Enumerator and the `.lazy` makes it an Enumeable::Lazy to keep the `.grep_v` from being eager.
<havenwood> The `.drop` is then lazy, and returns an Enumerable::Lazy.
<havenwood> And it gets rid of everything before the one we want.
<Sampersand> so tl;dr, what you're doing is given a string, you want to split it into two pieces, starting at 7. However, if there any `a` or `b` after index 7, then you want to only want to split after those are over?
<isene> But can I just dot them together with a method on each line?
<havenwood> With the `.first` it finally runs, grabbing just the first.
<havenwood> isene: Yeah, you can one liner-it.
<isene> Nice
<havenwood> The `&.last` is to get the index, if there is a character out that far.
<havenwood> Sampersand: Yup, find the index with the stuff removed, put them back and partition.
<isene> Thanks a plenty
<havenwood> isene: np!
<havenwood> I do think Samp is right that there are simpler versions that will work.
<Sampersand> im thinking of `\G` with `split`
<havenwood> Sampersand: hem
<havenwood> isene: This ^ one is optimized in a way that works great for very large or infinite Strings.
<Sampersand> i dont see how you get index 12 from the input `abcdaba123abcd`
<Sampersand> oh
<havenwood> Sampersand: The way I interpreted what isene said, I think `.delete('bc')` find index then add back those bcs.
<havenwood> Err, I said that badly, but yeah.
<Sampersand> `orig[orig.length - new.length + 7..]`
<isene> I'm very close now. All the usual stiff in curses is implemented: boxes with our without borders, text inside with justifying and all kinds of font dressing (bold, colours, revers, blink...), proper line breaking. And with editing inside the box. Text manipulations, cursor movements... the works. Less than 500 lines of code as we speak.
<isene> s/stiff/stuff/
<isene> Fucking autocorrect on the phone
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
eddof13 has joined #ruby
<Sampersand> i have now been nerd sniped lol
<Sampersand> i will figure this out
<Sampersand> havenwood does that `grep_v` actually doanything
<Sampersand> havenwood your thing doesnt work right if yotu do `str.tr!('bc', 'qq')`
<Sampersand> isene: try this `str =~ /^[bc]*([^bc][bc]*){7}/; p [$&, $']`
<Sampersand> we use a regex to match 7 characters that aren't `b` or `c` , while also matching an arbitrary amount of `b`s or `c`s
<isene> Regex hero lvl 21
<havenwood> Sampersand: Don't do `str.tr!('bc', 'qq')` with my solution! 🧟
<havenwood> Sampersand: Haha, nice!
<Sampersand> haven lol i meant at the start
<Sampersand> i think the example just happened to work with what you had
<havenwood> I was going to write it as a method but then wanted an initialize and was going to write it as a class but that seemed a bit much.
<Sampersand> isene that isn't as nearly as bad as it could've gotten! haha
<Sampersand> i was overthinking nit earlier
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
Sampersand has quit [Quit: Client closed]