News for hackers. Stuff that matters.
Re:Ruby 3.4 Highlights by anonnon on Wednesday January 01, 2025 @10:18AM (#42566500)
> In Ruby 3.4, it has been added as a default name for the first parameter passed to a block. Rather than specifying a name in trivial cases like the one above, you can now write:

> [

> "beige chinos",

> "blue jorts",

> "rainbow jorts",

> ].filter { it =~ /jorts/ }

> # => ["blue jorts", "rainbow jorts"]

This reminds me of Perl's $_ (which in Ruby is last line read from STDIN).

Re:Ruby 3.4 Highlights by jshmrsn on Wednesday January 01, 2025 @10:27AM (#42566566)
I am familiar with ‘it’ as a default closure input from Kotlin. From a quick search, that in turns seems to be inspired by Groovy.
Re:Ruby 3.4 Highlights by alex_muscar on Wednesday January 01, 2025 @01:59PM (#42568225)
This goes at least as far back as anaphoric macros: https://en.m.wikipedia.org/wiki/Anaphoric_macro.
Re:Ruby 3.4 Highlights by inopinatus on Wednesday January 01, 2025 @06:03PM (#42570035)
shame about that example, since

    ary.grep /(j|sh)orts/
already exists, and therefore sells the standard library short. try this:

    terms = %w(foo? bar q**x)
    Regexp.new "\\b(#{terms.map { Regexp.escape it }.join ?|})\\b"

    #=> /\b(foo\?|bar|q\*\*x)\b/
and observe that it's at the margins of instant comprehension where syntax shorthands like "it" add value.