havenwood changed the topic of #ruby to: Ruby 3.3.5 (3.4.0-preview1) https://www.ruby-lang.org | Logs https://libera.irclog.whitequark.org/ruby
mtm has quit [Ping timeout: 246 seconds]
<llua> you aren't storing a reference to the array, but #readlines creates one
mtm has joined #ruby
konsolebox has quit [Ping timeout: 252 seconds]
brw has quit [Quit: The Lounge - https://thelounge.chat]
brw has joined #ruby
konsolebox has joined #ruby
konsolebox has quit [Ping timeout: 240 seconds]
cappy has joined #ruby
gr33n7007h has quit [Ping timeout: 246 seconds]
konsolebox has joined #ruby
gr33n7007h has joined #ruby
Rounin has quit [Quit: Rounin]
pages has quit [Quit: ZNC - https://znc.in]
pages has joined #ruby
konsolebox has quit [Ping timeout: 260 seconds]
Munto has joined #ruby
paddymahoney has quit [Ping timeout: 276 seconds]
paddymahoney has joined #ruby
grenierm has joined #ruby
konsolebox has joined #ruby
klf has joined #ruby
<klf> Hello
<klf> inreplace "Makefile" do |s|
<klf> s.gsub! "/usr/local", HOMEBREW_PREFIX.to_s
<klf> q1) what does the |s| notation mean?
<klf> q2) what does the '!' in 's.gsub!' mean?
Linux_Kerio has joined #ruby
<klf> s apppears to be an instance of https://rubydoc.brew.sh/StringInreplaceExtension.html
<klf> but what is the `|...|` notation?
klf has quit [Quit: Leaving]
Triviality has quit [Ping timeout: 260 seconds]
<llua> a block argument
klf has joined #ruby
<constxd> klf: [02:12:51] <llua> a block argument
<klf> thank you; brb again
klf has quit [Client Quit]
klf has joined #ruby
<klf> what does the '!' in 's.gsub!' mean?
<klf> nvm, it appears that it's simply part of the method name
<llua> indeed
<llua> its a convention where the method modifies the object itself instead of returning a new object
<klf> A small follow-up to q1): In our example above, the block is a do-block, and the block argument is 's', denoted using the |s| notation.
<klf> so if the block accepts mulitple arguments, then are they specified as a comma separated list?
<klf> e.g. |a|,|b|,|c|
<llua> |a, b, c|
<klf> llua, great. It might be time to pick up the Ruby langauge as I find myself needing to tinker with homebrew. (TLDR; since I am still on a 2011 MBP runnning 10.15.7 and that the homebrew maintainers peeve at those running unsupported versions; Okay, I'll stop ranting now)
Pixi` has quit [Quit: Leaving]
klf has quit [Quit: Leaving]
Pixi has joined #ruby
klf has joined #ruby
klf has quit [Quit: Leaving]
sarna has quit [Remote host closed the connection]
sarna has joined #ruby
chen has quit [Ping timeout: 252 seconds]
Linux_Kerio has quit [Ping timeout: 252 seconds]
BSaboia has joined #ruby
grenierm has quit [Ping timeout: 256 seconds]
Artea has joined #ruby
Pixi` has joined #ruby
SaveFerris3 has joined #ruby
Quiet-Oil92622 has joined #ruby
meimei_ has joined #ruby
brw9 has joined #ruby
pounce_ has joined #ruby
caleb__ has joined #ruby
llua` has joined #ruby
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
dostoyev1ky2 has joined #ruby
gr33n7001 has joined #ruby
enyc_ has joined #ruby
Pixi has quit [*.net *.split]
gr33n7007h has quit [*.net *.split]
brw has quit [*.net *.split]
Artea has quit [*.net *.split]
ruby[bot] has quit [*.net *.split]
Starfoxxes has quit [*.net *.split]
itaipu has quit [*.net *.split]
llua has quit [*.net *.split]
caleb_ has quit [*.net *.split]
enyc has quit [*.net *.split]
pounce has quit [*.net *.split]
meimei has quit [*.net *.split]
dostoyevsky2 has quit [*.net *.split]
Quiet-Oil9262 has quit [*.net *.split]
SaveFerris has quit [*.net *.split]
infernix has quit [*.net *.split]
caleb__ is now known as caleb_
brw9 is now known as brw
Quiet-Oil92622 is now known as Quiet-Oil9262
meimei_ is now known as meimei
SaveFerris3 is now known as SaveFerris
pounce_ is now known as pounce
Starfoxxes has joined #ruby
itaipu has joined #ruby
Artea_ has joined #ruby
Artea_ has quit [Remote host closed the connection]
infernix has joined #ruby
Artea has joined #ruby
Rounin has quit [Quit: Rounin]
Triviality has joined #ruby
cappy has quit [Quit: Leaving]
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
konsolebox has quit [Quit: .]
konsolebox has joined #ruby
Obsdark has joined #ruby
Obsdark has quit [Changing host]
Obsdark has joined #ruby
mtm has quit [Ping timeout: 252 seconds]
mtm has joined #ruby
enyc_ is now known as enyc
dostoyev1ky2 has quit [Quit: leaving]
dostoyevsky2 has joined #ruby
mange has joined #ruby
llua` is now known as llua
rvalue has quit [Read error: Connection reset by peer]
rvalue has joined #ruby
Rounin has quit [Quit: Rounin]
Linux_Kerio has joined #ruby
kiwi_36 has joined #ruby
oneeyedalien has joined #ruby
<constxd> bros i got a little codegolf question how would u fill in nil values in one array with values from another array, and then put any leftover elements from the second array at the end
<constxd> for example: xs=[1, 2, None, 4, None, None, 7] and ys=['a', 'b', 'c', 'd', 'e', 'f']. then you want the result: [1, 2, 'a', 4, 'b', 'c', 7, 'd', 'e', 'f']
<leftylink> Array#map, Array#shift, and Array#+
<mange> More specifically: xs.map { _1.nil ? ys.shift : _1 } + ys
<leftylink> use ||
<mange> Whoops, forgot the ? for the nil? method.
<mange> The spec was only to replace nil, not false. :)
<leftylink> touche
<leftylink> how do I make the correct e for touche
<leftylink> touché
<mange> Search the internet for the word and copy+paste?
<constxd> ok that's very slick
<leftylink> I feel so sad when doing so, like I'm not doing things on my own power, but I guess I also failed to specify I don't want to feel sad
<constxd> can you think of a way without mutating ys?
<mange> myys = ys.dup; xs.map { _1.nil? ? myys.shift : _1 } + myys
<mange> I mean, yeah, you could keep track of the index instead and walk through the array yourself, but it will be more involved.
<mange> It's not *that* much worse, but I don't like it as much: i = 0; xs.map { _1.nil? ? ys[i += 1] : _1 } + ys[i..]
<constxd> hmm
<mange> Oh, wait, sorry, that's off by one. You'd have to start with i = -1
<mange> And use ys[(i + 1)..] at the end. I feel like the fact that I've made two off-by-one errors should point you towards the solution that doesn't involve numbers.
<constxd> this is driving me crazy
dviola has quit [Ping timeout: 260 seconds]
<mange> What is driving you crazy?
<constxd> i feel like there should be a very simple solution that doesn't involve any mutation
chen has joined #ruby
<constxd> consider this related problem too: you want to *add* the nil values to ys at the same indices. so you end up with: ['a', 'b', nil, 'c', nil, nil, 'd', 'e', 'f']
<constxd> then i think you can just interleave them and remove the nils
<mange> Why does it need to not involve mutation?
<constxd> no reason really just an exercise at this point
<mange> Here you go: yiter = ys.each; result = xs.map { _1.nil? ? yiter.next : _1 }; loop { result << yiter.next } rescue StopIteration; result
<constxd> the mutating solution will work fine for what i am actually doing
user71 has joined #ruby
<constxd> what is the type of yiter there
<mange> Like, you need to track the state of your iteration somehow. Using mutation does it implicitly, by removing values as you consume them. Using an index does it explicitly using random access. Using an enumerator does it implicitly using that protocol (which will work for non-array values like sets).
<constxd> then surely you don't need to do that stuff at the end?
<mange> Then how do you get the remaining values out of the enumerator?
<constxd> result = xs.map { _1.nil? ? yiter.next : _1 } + yiter.to_a
<constxd> idk i dont know ruby
<constxd> does that work?
<mange> You could just run that and find out yourself.
<mange> The short answer is: no.
<constxd> wait what it seems to work when i run it
<constxd> well let me try the entire expression
<mange> Really? For me yiter.to_a on the end returns the entirety of ys again.
<constxd> hmm that seems like odd behaviour doesn't it
<constxd> is there a way to make it forget that it's backed by an array and just get like a pure generator so it can't reset itself on the .to_a call
<mange> I don't know.
<mange> But you now have three solutions to your problem, so I'm going to bed. :)
<constxd> haha good night
mange has quit [Quit: Zzz...]
oneeyedalien has quit [Ping timeout: 248 seconds]
royo25 has joined #ruby
royo25 has quit [Quit: Bye]
passbe24 has quit [Quit: bye...]
passbe24 has joined #ruby
chen has quit [Ping timeout: 260 seconds]
Rounin has joined #ruby
Perflosopher has quit [Ping timeout: 260 seconds]
Triviality has quit [Ping timeout: 255 seconds]
Perflosopher has joined #ruby
Rounin has quit [Quit: Rounin]
johnjaye has quit [Ping timeout: 276 seconds]
Rounin has joined #ruby
Rounin has quit [Changing host]
Rounin has joined #ruby
Perflosopher4 has joined #ruby
Perflosopher has quit [Ping timeout: 255 seconds]
Perflosopher4 is now known as Perflosopher
oneeyedalien has joined #ruby
oneeyedalien has quit [Quit: Leaving]
chen has joined #ruby
rvalue- has joined #ruby
rvalue has quit [Ping timeout: 252 seconds]
rvalue- is now known as rvalue
royo25 has joined #ruby
royo25 has quit [Quit: Bye]
royo25 has joined #ruby
royo25 has quit [Quit: Bye]
Goodbye_Vincent has quit [Remote host closed the connection]
Goodbye_Vincent1 has joined #ruby
konsolebox has quit [Quit: .]
Linux_Kerio has quit [Ping timeout: 272 seconds]
dviola has joined #ruby
dviola has quit [Client Quit]
user71 has quit [Quit: Leaving]
dviola has joined #ruby
d0htemsf has joined #ruby
Success has quit [Ping timeout: 260 seconds]
kiwi_36 has quit [Ping timeout: 245 seconds]
kiwi_36 has joined #ruby
Obsdark has quit [Quit: Nettalk6 - www.ntalk.de]
ruby[bot] has joined #ruby
ua_ has quit [Ping timeout: 248 seconds]
d0htemsf has quit [Quit: Connection closed for inactivity]
ua_ has joined #ruby