Numbered Parameters for Ruby 2.7

Numbered Parameters for Ruby 2.7
Average rating: 0
(0 votes)

There is not a week without Ruby topics. Ruby 2.7 is coming out this December, as with all modern releases, but it’s already some information available on what vital things to expect from this version! As for example, we’d like to talk about Numbered Parameters for Ruby 2.7.

Considering block with positional arguments, especially single positional, you can do the following:

.map { @1 + 3 }

Here @1 is the first parameter to the block function.

  • Numbered parameters are only valid when referenced inside of a block
  • A numbered param has to follow a few rules, namely there are only numbers in it and 0 along with leading 0s are errors
  • Say we have collections or even hashes, we can use @2 and further if we need them to get at the specific values
  • Ruby doesn’t like mix-and-match with our current way of doing block parameters
  • It would be good to remember that @1 and friends are just Ruby objects, meaning we can call anything on them that we would a parameter

Here you can find the commit, and here you can read more from Brandon Weaver.

Read more on the Shrine, a file attachments toolkit for Ruby applications if you somehow missed it. Or take a look at a scope of the most interesting and promising Ruby repositories in March collected in our latest Ruby on Rails digest!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Phone (+1) 9035021111