Live data from Hacker News

Ruby 3.4 Highlights

blog.sinjakli.co.uk

1–10 of 86 posts

Re: Ruby 3.4 Highlights

#3
> 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

#7
post #3

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

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

#9

The default block parameter name seems small, but I feel like I'm gonna use it all the time, especially when I'm in the Rails console just trying to debug data

Kotlin also has it, I can tell you that it's really useful

Ruby has had this in the same form as "_1" for a while (and the obvious other indexes in the case of multiple params), but I agree Kotlin's "it" reads much better.

Re: Ruby 3.4 Highlights

#10
I happen to be reading the latest edition of the pickaxe book, as I'll soon be using Ruby at work (first experience) and this 'it' update sounds so much better than the _1 described in the book.

I remember thinking it clashed a bit with the idea of trying to make the code read like natural language.

Post reply on HN