Today I Learned

A Hashrocket project

Full O' Features Ruby 2.7 has Numbered Arguments

The last TIL maybe wasn’t that useful, but you can expect to see this new language feature in a ruby file near you very soon.

> [1, 2, 3, 4].map {_1 + 1}
[2, 3, 4, 5]

Numbered Arguments! The _1 is a reference to the variable that would usually be between the pipes {|x| + 1}

So what if it’s not zero based :).

Looking for help? Each developer at Hashrocket has years of experience working with Ruby applications of all types and sizes. We're an active presence at Ruby conferences, have written some of the most popular gems, and have worked on many of the web's Ruby on Rails success stories. Contact us today to talk about your Ruby project.