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.
> [
> "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).