adam12 changed the topic of #ruby to: Rules: https://ruby-community.com | Ruby 2.7.2, 2.6.6, 3.0.0-preview2: https://www.ruby-lang.org | Paste 4+ lines of text to https://dpaste.org | Books: https://goo.gl/wpGhoQ | Logs: https://irclog.whitequark.org/ruby | BLM <3
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
thecoffemaker has joined #ruby
thecoffemaker has quit [Max SendQ exceeded]
drincruz has joined #ruby
thecoffemaker has joined #ruby
braincrash has quit [Ping timeout: 240 seconds]
drincruz has quit [Ping timeout: 240 seconds]
gavlee has quit [Ping timeout: 265 seconds]
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
thecoffemaker has joined #ruby
drincruz has joined #ruby
thecoffemaker has quit [Max SendQ exceeded]
TCZ has joined #ruby
thecoffemaker has joined #ruby
aremaref has joined #ruby
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
thecoffemaker has joined #ruby
_whitelogger has joined #ruby
* nakilon just realised that "mtd{ ... }" isn't the same as "mtd &->{ ... }"
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
thecoffemaker has joined #ruby
thecoffemaker is now known as thecoffem
aremaref has quit [Ping timeout: 240 seconds]
thecoffem has quit [Quit: So long and thanks for all the fish!]
prion has joined #ruby
<prion> hi
<prion> how can i write this better
<prion> $stdin.readlines.map { |s| s.chomp }
Rudd0 has quit [Ping timeout: 240 seconds]
<leftylink> readlines takes keyword argument chomp
<nakilon> STDIN.readlines.map &:chomp
<nakilon> STDIN.read.split "\n"
<nakilon> $<.read.split ?\n
<prion> &:chomp that's what i was looking for
<rubydoc__> prion: parser error ["Expected \">>\", but got ", ":c"@0] at position 0 around `:'
<nakilon> [*$<].map &:chomp
<prion> is &:foo always equivalent to { |x| x.foo }
<leftylink> &ri Symbol#to_proc
<leftylink> is the answer to that question
<prion> ok i have so many questions
<prion> why STDIN over $stdin, and is $< just an alias for $stdin?
<nakilon> I believe they are answered at Stackoverflow
<leftylink> hmm, I should keep the link handy
pinkpandabot has joined #ruby
<leftylink> pinkpandabot: learn rubyglobals https://docs.ruby-lang.org/en/2.7.0/doc/globals_rdoc.html
<pinkpandabot> Learned new fact rubyglobals; 38 facts total
<nakilon> keep the link lefty
thecoffemaker has joined #ruby
<nakilon> you better remove /2.7.0/ substring from urls or they'll get "outdated" in a year
<nakilon> oh, that site can't do that redirect
<nakilon> another site that you said "isn't official" can
* nakilon afk
<prion> ruby is based
<prion> ok let's say i have ["abc", "10"] and i want to get ["abc", 10]
<prion> or like i wanna do a, b = ["abc", "10"]; b = b.to_i
<prion> but all in one go so it's not ugly
<CommunistWolf> ary.map { |a| a.match?(/\A\d+\z/) ? a.to_i : a }
<CommunistWolf> well, I guess: a, b = ary.map { |a| a.match?(/\A\d+\z/) ? a.to_i : a }
<CommunistWolf> ish
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
<prion> that works, idk if it's preferable to the two liner though
thecoffemaker has joined #ruby
dfucci has joined #ruby
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
<leftylink> eh, so that'd be something similar to Haskell's Control.Arrow.first or Control.Arrow.second ... AFAIK Ruby doesn't have such a thing
thecoffemaker has joined #ruby
thecoffemaker has quit [Max SendQ exceeded]
<leftylink> &>> def second(&f) ->((a,b)) { [a, f[b]] } end; second(&:to_i)[["abc", "10"]]
<rubydoc__> # => ["abc", 10] (https://carc.in/#/r/a3sc)
<leftylink> well that code looks quite unreasoable
<leftylink> I would never actually do such a thing
bamdad has quit [Remote host closed the connection]
bambanx has quit [Quit: Leaving]
hiroaki has quit [Ping timeout: 272 seconds]
drincruz has quit [Ping timeout: 240 seconds]
gdonald has joined #ruby
drincruz has joined #ruby
thecoffemaker has joined #ruby
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dfucci has quit [Ping timeout: 265 seconds]
gdonald has quit [Quit: leaving]
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
thecoffemaker has joined #ruby
drincruz has quit [Ping timeout: 260 seconds]
evdubs_ has joined #ruby
Technodrome has joined #ruby
evdubs has quit [Ping timeout: 260 seconds]
Garb0 has quit [Ping timeout: 272 seconds]
thecoffemaker has quit [Read error: Connection timed out]
thecoffemaker has joined #ruby
thecoffemaker has quit [Max SendQ exceeded]
thecoffemaker has joined #ruby
banisterfiend has joined #ruby
thecoffemaker has quit [Quit: So long and thanks for all the fish!]
ChmEarl has quit [Quit: Leaving]
thecoffemaker has joined #ruby
electrostat has quit [Ping timeout: 246 seconds]
TCZ is now known as TCZ_2077
electrostat has joined #ruby
ur5us has joined #ruby
TCZ_2077 has quit [Quit: Diabe? tkwi w szczegó?ach]
helpa has quit [Remote host closed the connection]
helpa has joined #ruby
HyFlex has joined #ruby
<HyFlex> Hi, is anyone able to help my with my question? I posted it on stackoverflow if anyone wants to look:
Rudd0 has joined #ruby
HyFlex has quit [Ping timeout: 256 seconds]
dfucci has joined #ruby
HyFlex has joined #ruby
gix has joined #ruby
HyFlex has quit [Client Quit]
gix- has quit [Ping timeout: 240 seconds]
drincruz has joined #ruby
prion has quit [Ping timeout: 265 seconds]
drincruz has quit [Ping timeout: 265 seconds]
znz_jp has quit [Remote host closed the connection]
znz_jp has joined #ruby
cuerbot has quit [Read error: Connection reset by peer]
elcuervo has joined #ruby
dfucci has quit [Ping timeout: 256 seconds]
cowgomoo has quit [Remote host closed the connection]
prion has joined #ruby
Swyper has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 260 seconds]
Emmanuel_Chanel has joined #ruby
banisterfiend has quit [Read error: Connection reset by peer]
apotheon has quit [Ping timeout: 240 seconds]
apotheon has joined #ruby
adu has joined #ruby
greenbagels has quit [Quit: WeeChat 2.3]
pinkpandabot has quit [Quit: new aoc session...]
dfucci has joined #ruby
dfucci has quit [Ping timeout: 258 seconds]
SaintNickname has joined #ruby
pwnd_sfw5 has joined #ruby
pwnd_sfw has quit [Ping timeout: 256 seconds]
pwnd_sfw5 is now known as pwnd_sfw
adu has quit [Quit: adu]
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
blackmesa1 has joined #ruby
cd has quit [Quit: cd]
Swyper has joined #ruby
Swyper has quit [Ping timeout: 260 seconds]
SaintNickname has quit [Remote host closed the connection]
<KrzaQ> Is there a way to format a #{} interpolated string? E.g. I'd want something like "Foo: #{.3f:1.0/3}" to display 'Foo: 0.33'
blackmesa1 has quit [Ping timeout: 260 seconds]
blackmesa1 has joined #ruby
akem__ has joined #ruby
akem_ has quit [Ping timeout: 240 seconds]
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
orbyt_ has joined #ruby
dfucci has joined #ruby
mozzarella has quit [Ping timeout: 240 seconds]
dfucci has quit [Ping timeout: 240 seconds]
<apotheon> KrzaQ: "Foo: #{ "%.3f" % (1.0 / 3) }"
akem__ is now known as Chew
Chew is now known as Cheww
<KrzaQ> At this point I can use % directly. But thanks. I wasn't even sure how to google that question
<leftylink> cd hmm
<leftylink> "formatting in ruby string interpolation" or something
<KrzaQ> yeah, that returned a bunch of results for Kernel::sprintf/%
<apotheon> KrzaQ: Don't forget "format" as well as "sprintf" and "%".
orbyt_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
braincrash has joined #ruby
naftilos76 has joined #ruby
<naftilos76> Hi every one. I am trying to use the queue class inside ruby threads. It seems to work fine until all threads reach the point where queue.length equals zero and then i get "No live threads left. Deadlock?"
<naftilos76> Code and output ^
lucidreamachine has quit [Remote host closed the connection]
lucidreamachine has joined #ruby
<naftilos76> Could it be that i simply have to set some kind of property of the Thread class in order to allow threads blocked for ever?
al2o3-cr has joined #ruby
<naftilos76> until the next task is added to the queue off course
<leftylink> hmm... well, certainly the output is telling the truth - there are no more live threads, because of the join. wouldn't a more accurate test be to have to main thread sleep for a number of seconds, then push another batch of tasks in?
<leftylink> and then sleep again
<leftylink> or I guess after the second batch of tasks then `join` is "fine" as in it'll not wait too long but still demonstrate that the threads were woken up
<leftylink> the comment on line 25 is wrong
<leftylink> join is not needed to execute the threads
dfucci has joined #ruby
<naftilos76> leftylink: i intentionally put those comments just in case i have the wrong idea. Then why is join used after all?
<leftylink> join is used when you need to wait for the thread to exit. for example, if you absolutely cannot proceed without the thread having completed. note that in this case it doesn't make sense to `join` on those threads, since they *never* exit
<naftilos76> so your telling me that i do not need to join those threads at all?
dfucci has quit [Ping timeout: 256 seconds]
<leftylink> well, why do people join threads at all. if one runs `ruby -e "Thread.new { puts :yes }"`, one will likely never see any output at all, because the program exits before the thread prints yes
<naftilos76> i just commented the join expression and all i go was "Thread id: 0, tasks waiting: 0" and the process exited
<naftilos76> it is clear that i do not have a solid understanding of what is going on here
<leftylink> for the same reason as why `ruby -e "Thread.new { puts :yes }"` prints nothing
<leftylink> program exits before thread prints
<naftilos76> ok thanks for your time
weaksauce has quit [Ping timeout: 258 seconds]
evdubs_ is now known as evdubs
drincruz has joined #ruby
vondruch has quit [Read error: Connection reset by peer]
aremaref has joined #ruby
drincruz has quit [Ping timeout: 264 seconds]
aremaref has quit [Ping timeout: 246 seconds]
hiroaki has joined #ruby
dfucci has joined #ruby
tfk has joined #ruby
iNs has quit [Ping timeout: 240 seconds]
Cheww has quit [Ping timeout: 240 seconds]
iNs has joined #ruby
blackmesa1 has quit [Ping timeout: 265 seconds]
Technodrome has joined #ruby
tfk has quit [Quit: tfk]
w0rstpr0grammer_ has joined #ruby
w0rstpr0grammer_ has quit [Quit: w0rstpr0grammer_]
blackmesa1 has joined #ruby
blackmesa1 has quit [Ping timeout: 264 seconds]
_aeris_ has quit [Remote host closed the connection]
_aeris_ has joined #ruby
Xiti has quit [Read error: Connection reset by peer]
Xiti has joined #ruby
akem has joined #ruby
akem_ has joined #ruby
akem has quit [Ping timeout: 256 seconds]
w0rstpr0grammer_ has joined #ruby
w0rstpr0grammer_ is now known as w0rstpr0grammer
somazero has joined #ruby
somazero has quit [Remote host closed the connection]
batisi[m] has joined #ruby
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
w0rstpr0grammer has quit [Quit: w0rstpr0grammer]
w0rstpr0grammer has joined #ruby
w0rstpr0grammer has quit [Quit: w0rstpr0grammer]
w0rstpr0grammer has joined #ruby
BSaboia has joined #ruby
Swyper has joined #ruby
* nakilon woke up
<nakilon> >> ["abc", "10"].map{ |i| Integer i rescue i }
<ruby[bot]> nakilon: # => ["abc", 10] (https://carc.in/#/r/a3uv)
<nakilon> prion
w0rstpr0grammer has quit [Quit: w0rstpr0grammer]
blackmesa1 has joined #ruby
blackmesa1 has quit [Read error: Connection reset by peer]
<prion> lmfao
<prion> i wish write like ["abc", "10"].on(1, &:to_i)
<prion> i wish i could*
<prion> or ["abc", "10"].map_if(/\d+/, &:to_i)
blackmesa1 has joined #ruby
blackmesa1 has quit [Ping timeout: 264 seconds]
iamgr00t_ has joined #ruby
iamgr00t has quit [Ping timeout: 260 seconds]
batisi[m] has quit [Ping timeout: 260 seconds]
batisi[m] has joined #ruby
lucasb has joined #ruby
blackmesa1 has joined #ruby
blackmesa1 has quit [Ping timeout: 264 seconds]
TCZ has joined #ruby
Mia has joined #ruby
Mia has quit [Changing host]
Mia has joined #ruby
junaidnaseer2 has joined #ruby
junaidnaseer2 has quit [Remote host closed the connection]
lucidreamachine has quit [Ping timeout: 258 seconds]
gavlee has joined #ruby
akem_ has quit [Ping timeout: 256 seconds]
arahael has quit [Ping timeout: 240 seconds]
<nakilon> >> Encoding::default_internal = Encoding::default_external = "ASCII-8BIT"; "\x00\x0A\xFF\x00".inspect
<ruby[bot]> nakilon: # => "\"\\x00\\n\\xFF\\x00\"" (https://carc.in/#/r/a3vw)
lucidreamachine has joined #ruby
<nakilon> why is it => "\"\\u0000\\n\\xFF\\u0000\"" for me?
<nakilon> in irb
arahael has joined #ruby
ruurd has quit [Quit: ZZZzzz…]
Emmanuel_Chanel has quit [Quit: Leaving]
Emmanuel_Chanel has joined #ruby
ruurd has joined #ruby
lucidreamachine has quit [Quit: Leaving]
somazero has joined #ruby
TCZ has quit [Remote host closed the connection]
Swyper has quit []
w0rstp0grammer has joined #ruby
w0rstp0grammer has quit [Remote host closed the connection]
<havenwood> &>> ["abc", "10"].map { Integer(_1, exception: false) || _1 } # prion
<rubydoc__> # => ["abc", 10] (https://carc.in/#/r/a3w1)
iNs has quit [Remote host closed the connection]
iNs has joined #ruby
blackmesa1 has joined #ruby
hiroaki has quit [Ping timeout: 264 seconds]
brunosaboia_ has joined #ruby
iNs has quit [Remote host closed the connection]
iNs has joined #ruby
TCZ has joined #ruby
BSaboia has quit [Ping timeout: 264 seconds]
dfucci has quit [Ping timeout: 240 seconds]
cuerbot has joined #ruby
elcuervo has quit [Ping timeout: 256 seconds]
ua_ has quit [Ping timeout: 240 seconds]
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dfucci has joined #ruby
blackmesa has joined #ruby
blackmesa1 has quit [Ping timeout: 258 seconds]
dfucci has quit [Ping timeout: 240 seconds]
kaivai has quit [Quit: ZNC - https://znc.in]
cd has joined #ruby
kaivai has joined #ruby
ua_ has joined #ruby
dfucci has joined #ruby
brunosaboia_ has quit [Quit: Leaving]
dfucci has quit [Ping timeout: 260 seconds]
ChmEarl has joined #ruby
darris has quit [Ping timeout: 256 seconds]
blender has quit [Ping timeout: 260 seconds]
darris has joined #ruby
blender has joined #ruby
maryo has joined #ruby
dfucci has joined #ruby
blackmesa has quit [Ping timeout: 264 seconds]
dfucci has quit [Ping timeout: 272 seconds]
defdom0 has joined #ruby
dfucci has joined #ruby
TCZ has quit [Remote host closed the connection]
mozzarella has joined #ruby
dfucci has quit [Ping timeout: 264 seconds]
defdom0 has quit [Quit: defdom0]
defdom0 has joined #ruby
defdom0 has quit [Client Quit]
adu has joined #ruby
Technodrome has joined #ruby
dfucci has joined #ruby
somazero has quit [Remote host closed the connection]
dfucci has quit [Ping timeout: 240 seconds]
mcspud has quit [Ping timeout: 272 seconds]
blackmesa has joined #ruby
blackmesa1 has joined #ruby
blackmesa has quit [Ping timeout: 260 seconds]
blackmesa1 has quit [Ping timeout: 265 seconds]
mcspud has joined #ruby
dfucci has joined #ruby
blackmesa1 has joined #ruby
dfucci has quit [Ping timeout: 256 seconds]
jinie has quit [Ping timeout: 260 seconds]
dfucci has joined #ruby
jinie has joined #ruby
dfucci has quit [Ping timeout: 240 seconds]
adu has quit [Quit: adu]
braincrash has quit [Ping timeout: 272 seconds]
Caerus has quit [Ping timeout: 260 seconds]
Caerus has joined #ruby
jinie has quit [Ping timeout: 272 seconds]
dfucci has joined #ruby
blackmesa1 has quit [Ping timeout: 260 seconds]
orbyt_ has joined #ruby
Caerus has quit [Ping timeout: 246 seconds]
jinie has joined #ruby
dfucci has quit [Ping timeout: 240 seconds]
blackmesa1 has joined #ruby
braincrash has joined #ruby
drincruz has joined #ruby
blackmesa1 has quit [Ping timeout: 264 seconds]
Rudd0 has quit [Read error: Connection reset by peer]
Caerus has joined #ruby
blackmesa1 has joined #ruby
braincrash has quit [Ping timeout: 240 seconds]
blackmesa1 has quit [Ping timeout: 260 seconds]
Technodrome has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
DTZUZU has joined #ruby
TCZ has joined #ruby
dfucci has joined #ruby
ur5us has joined #ruby
aremaref has joined #ruby
hiroaki has joined #ruby
braincrash has joined #ruby
<tempate> Hello. How can I remove an element from an array at a certain index and get the array itself as the return type, instead of the element I just deleted?
maryo has quit [Ping timeout: 265 seconds]
prion has quit [Ping timeout: 240 seconds]
canton7 has quit [Quit: ZNC - http://znc.in]
canton7 has joined #ruby
<leftylink> there shouldn't be any shame in doing a = [1, 2, 3]; a.delete_at(1); a. but if you must, a.tap { a.delete_at(1) }
<leftylink> &>> a = [1, 2, 3]; a.tap { a.delete_at(i) }
<rubydoc__> stderr: -e:4:in `block in <main>': undefined local variable or method `i' for main:Object (NameError)... check link for more (https://carc.in/#/r/a3wk)
<leftylink> &>> a = [1, 2, 3]; a.tap { a.delete_at(1) }
<rubydoc__> # => [1, 3] (https://carc.in/#/r/a3wl)
<leftylink> I obviously meant 1
dfucci has quit [Ping timeout: 256 seconds]
<havenwood> &>> [1, 2, 3].tap { _1.delete_at 1 }
<rubydoc__> # => [1, 3] (https://carc.in/#/r/a3wm)
<tempate> I see
<al2o3-cr> &>> %i(foo bar baz).reject.with_index { _2 == 1 }
<rubydoc__> # => [:foo, :baz] (https://carc.in/#/r/a3wn)
<leftylink> o. that's handy (because no mut)
<al2o3-cr> leftylink: yes in this case it doesn't mutate the receiver.
<tempate> Right now I have something like https://dpaste.org/yOCr/slim, but it doesn't seem like the right way
<leftylink> I sorta respect that, but if they're going to be multiplied and one factor shouldn't be multiplied, I also suggest multiplying them all and mapping over it via division of individual elements
<tempate> Yeah, that's another way to go about it, sure
<tempate> I thought I may be missing out on something fancier
<leftylink> Ruby 3.0 gets Hash#except, though I don't think there's Array#except yet...
<tempate> Is there a way for me to multiply all the :ids together or do I have to use a map?
naftilos76 has quit [Ping timeout: 264 seconds]
<leftylink> no, if this were a sum then it'd be possible to use buses.sum { |bus| bus[:id] }, but no such convenience for product
<leftylink> actually... I think sum takes some arguments? let me investigate...
rapha has quit [Ping timeout: 256 seconds]
<leftylink> &ri Enumerable#sum
<leftylink> hmmmmmmm no, it doesn't also let you specify the combiner, that'd be reduce
naftilos76 has joined #ruby
<leftylink> too bad
naftilos76 has quit [Read error: No route to host]
<havenwood> tempate: reduce might looks something like: https://gist.github.com/havenwood/3c90a75b5aa0795919f18b2c9c077154
<havenwood> oops, not 0
<havenwood> fixed, ish
<leftylink> I could have sworn the precedence is going to get you there
<havenwood> leftylink: yup, it will
<leftylink> okay yeah the precedence is absolutely not right for that
<havenwood> leftylink: okay, fixed
<havenwood> leftylink: making errors faster than fixing them :O
<tempate> havenwood: oh, nice, thanks
<havenwood> tempate: np
<tempate> I think I'm going to end up going for something like: https://dpaste.org/CjCF
<tempate> It seems like the most readable option to me
<leftylink> if performance was really important, I would really stress that that entire term, `schedules.map{ |schedule| schedule[:id] }.inject(:*) `, should be pulled out and computed once only
<leftylink> but it doesn't matter for the input size given so whatever
<leftylink> but I still suggest it on principle.
<tempate> leftylink: oh, yeah, right...
<leftylink> as you can see, it doesn't depend on i
<leftylink> indeed
<tempate> I'll do it, why not
<tempate> Is there a difference between .inject(&:*) and .inject(:*) ?
aremaref has quit [Ping timeout: 240 seconds]
<havenwood> tempate: Same functionality.
<havenwood> tempate: many folk these days would use the alias: reduce(:*)
<havenwood> &>> [1, 2, 3].reduce(:*)
<rubydoc__> # => 6 (https://carc.in/#/r/a3wv)
stonerl has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
<havenwood> &>> [].reduce(:*)
<rubydoc__> # => nil (https://carc.in/#/r/a3ww)
<tempate> I understand that & is used for operators that are intrinsic to the object, such as .inject(&:to_i), right?
aremaref has joined #ruby
<tempate> havenwood: yeah, I've got that feeling. I like the inject alias for some reason.
<havenwood> tempate: The & does two things. It calls #to_proc on what's being passed and passes it as a block.
<havenwood> :to_i.to_proc
<havenwood> as a block
<havenwood> &>> :to_i.class
<rubydoc__> # => Symbol (https://carc.in/#/r/a3wx)
stonerl has joined #ruby
<havenwood> &>> :to_i.to_proc
<rubydoc__> # => #<Proc:0x000055894a9179f8(&:to_i)> (https://carc.in/#/r/a3wy)
<tempate> Hmmm
<tempate> Interesting
<havenwood> &>> [].reduce(1, :*)
<rubydoc__> # => 1 (https://carc.in/#/r/a3wz)
<havenwood> &>> [1, 2, 3].reduce(1, :*)
<rubydoc__> # => 6 (https://carc.in/#/r/a3x0)
<havenwood> tempate: Would you want an empty Array to be `nil` or `1` or is it never empty?
<tempate> It shouldn't be empty, no
<tempate> Oh, another question: I don't like having to repeat .to_i here (https://dpaste.org/u77S); is there a way to avoid it?
<tempate> Well, not sure if it'd even make sense as it can be 'x'
<havenwood> tempate: input[1].split(',').map(&:id).map.with_index {
<havenwood> tempate: oops, I mean: map(&:to_i)
<havenwood> tempate: input[1].split(',').map(&:to_i).map.with_index {
<havenwood> tempate: Or does the "x" matter and can't be converted?
<tempate> What would that do if an element is not convertible to integer?
prion has joined #ruby
<havenwood> tempate: #to_i is lax and #Integer is strict
<havenwood> tempate: ''.to_i
<havenwood> #=> 0
<tempate> havenwood: the xs are worthless but the index of numbers matters
<leftylink> or we can have some uh suspicious code like this
<havenwood> &>> Integer('', exception: false) => nil
<rubydoc__> stderr: -e:4: syntax error, unexpected =>, expecting `end'... check link for more (https://carc.in/#/r/a3x1)
<havenwood> &>> Integer('', exception: false)
<rubydoc__> # => nil (https://carc.in/#/r/a3x2)
<leftylink> &>> xs = "1,x,3"; xs.split(?,).map { |x| {id: id = Integer(x, exception: false), id_again: id, id_yet_again: id} }
<rubydoc__> # => [{:id=>1, :id_again=>1, :id_yet_again=>1}, {:id=>nil, :id_again=>nil, :id_yet_again=>nil}, {:id=>3, :id_again=>3, :id_yet_again=>3}] (https://carc.in/#/r/a3x3)
<havenwood> tempate: It's cheap to `map(&:to_i)` in a small collection or a local variable inside the block would do the trick.
<tempate> havenwood: yeah, I liked that. I'm going for it.
<tempate> Once again, just to be clear, this: schedules.map{ |schedule| schedule[:id] }, can't be simplified, right?
<leftylink> I wish it could. if it were a struct instead, then schedules.map(&:id). but it's not a struct it's a hash. and no Ruby 2.7 means no schedules.map { _1[:id] }
blackmesa1 has joined #ruby
duderonomy has joined #ruby
blackmesa1 has quit [Ping timeout: 258 seconds]
aremaref has quit [Ping timeout: 256 seconds]
<tempate> sad
<havenwood> leftylink: tempate: but in those earlier Rubies you can: schedules.map { |id:| id }
<tempate> It feels kind of dirty, doesn't it?
<havenwood> &>> [{aim: true, dirty: true}].map { |aim:, dirty:| "#{aim} and #{dirty}" }
<rubydoc__> # => ["true and true"] stderr: -e:4: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call... check link for more (https://carc.in/#/r/a3x8)
<havenwood> (No warning pre-2.7.)
Rudd0 has joined #ruby
<leftylink> hmm. I would maybe have considered using that, but I guess if it's a warning then no
<havenwood> leftylink: Only a warning approaching 3.0.
<havenwood> leftylink: Pre-2.7 it's fine.
<havenwood> leftylink: But yeah, not future-looking good.
<havenwood> leftylink: Well, we'll see.
<tempate> I'm running 2.5 now but I'm not sure how I feel about using deprecated stuff
<havenwood> leftylink: Kwargs are a very late decision for 3.0.
<havenwood> tempate: We'll know within a few weeks if that deprecation warning is sticking.
<tempate> havenwood: what version is coming out?
<havenwood> tempate: 3.0 on Christmas.
<havenwood> tempate: Major update! :)
blackmesa1 has joined #ruby
<havenwood> tempate: Less than two weeks, and Ruby 3.0 is out.
aremaref has joined #ruby
drincruz has quit [Ping timeout: 256 seconds]
IsoLinCHiP has quit [Quit: WeeChat 2.3]
drincruz has joined #ruby
aremaref has quit [Ping timeout: 265 seconds]
<nakilon> what does "removal of WEBrick" mean? gemifying?
drincruz has quit [Ping timeout: 265 seconds]
<havenwood> nakilon: Yeah, gemifying then removing from stdlib rather than shipping as a bundled gem.
<havenwood> nakilon: (Both options are on the table, since a few other stdlib like un and rubygems use it.
<havenwood> )
braincra- has joined #ruby
braincrash has quit [Ping timeout: 256 seconds]
<nakilon> not quite sure what's the purpose... is it for compatibility between OSs?
TCZ has quit [Quit: P?o lesie przechadza sie zamyslony Zygfryd]
prion has quit [Ping timeout: 240 seconds]
<havenwood> nakilon: yup, just that
<nakilon> httpd is a handy thing -- I used it to test port forwarding
braincra- has quit [Ping timeout: 256 seconds]
<nakilon> it didn't need all the abilities of webrick though, just respond anything when I open a link in browser or curl
<tempate> havenwood: oh, nice!
prion has joined #ruby
<tempate> havenwood: before you said .map(&:to_i) is quite cheap; why is that?
Technodrome has joined #ruby
dfucci has joined #ruby
blackmesa has joined #ruby
blackmesa1 has quit [Ping timeout: 260 seconds]
TCZ has joined #ruby
TCZ has quit [Client Quit]
TCZ has joined #ruby
thecoffemaker has quit [Ping timeout: 240 seconds]
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
prion has quit [Ping timeout: 260 seconds]
dfucci has quit [Ping timeout: 256 seconds]
thecoffemaker has joined #ruby
weaksauce has joined #ruby
gdonald has joined #ruby
joast has quit [Quit: Leaving.]
joast has joined #ruby
blackmesa has quit [Ping timeout: 258 seconds]
<havenwood> tempate: The &:to_i parses a bit faster than a full block variant, so two of them can be faster than one full block (in this case, there's a full block subsequently, so not faster). A #to_i is fast, so with small collections the whole thing is kinda hand wavey quick. Benchmarks also vary by Ruby implementation. My main point is that the relative expense of either way is quite small with extremely quick methods like this one on anything that's not
<havenwood> huge.