News for hackers. Stuff that matters.
Re:Ruby 3.4.0 by evjan on Wednesday December 25, 2024 @02:26AM (#42507482)
‘it’ is a welcome addition!
Re:Ruby 3.4.0 by ciconia on Wednesday December 25, 2024 @03:28AM (#42507683)
Re:Ruby 3.4.0 by ilvez on Wednesday December 25, 2024 @05:04AM (#42507987)
Truly is, much nicer than that lonely `_1`
Re:Ruby 3.4.0 by rubyfan on Wednesday December 25, 2024 @11:23PM (#42513094)
_2 can be as bad as _1
Re:Ruby 3.4.0 by BoingBoomTschak on Thursday December 26, 2024 @05:59AM (#42514463)
I'd have thought allowing _ as a synonym for _1 would have been more aesthetically consistent. That's the path I went with when designing my CL #λ reader macro, personally.
Re:Ruby 3.4.0 by JasserInicide on Wednesday December 25, 2024 @08:57AM (#42508785)
I don't understand the point of it when the `.map(&:upcase)` syntax is shorter. This just seems like yet another syntactic sugar Rubyism that doesn't really add anything.

If it's an alternative to the `|x|` syntax when using only one block variable, then I like that.

Re:Ruby 3.4.0 by graypegg on Wednesday December 25, 2024 @09:00AM (#42508798)
That only works when calling a method on the things you’re iterating thru, it is a replacement for the single variable block example you gave there
Re:Ruby 3.4.0 by Trasmatta on Wednesday December 25, 2024 @09:10AM (#42508840)
`arr.map { it.thing.blah.stuff }`

The `&:` doesn't work in that context

Re:Ruby 3.4.0 by ilvez on Wednesday December 25, 2024 @01:25PM (#42510254)
Not to point any fingers, but shows that the previous commenter have not struggled with this :)

&: is very nice, but not enough.

Re:Ruby 3.4.0 by zachrose on Wednesday December 25, 2024 @06:27PM (#42511933)
Does `it` conflict with Rspec's `it`? Surely they've thought of this, but to my eye it looks like it would get confusing.
Re:Ruby 3.4.0 by prh8 on Wednesday December 25, 2024 @06:59PM (#42512082)
Nope it doesn’t, they did take that into account during development.