Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby block/anonymous function placeholder parameter

Tags:

ruby

I'm looking for the following syntax in Ruby[1,2,3].map {|n| f(n)} -> [1,2,3].map(f(_)). In Scala it's called a placeholder parameter.

Would it be possible to implement in ruby itself? Are there plans of adding some form of this syntax to the ruby language?

like image 850
Juliusz Avatar asked Dec 15 '25 05:12

Juliusz


1 Answers

There isn't yet, but it may happen soon. The most likely syntax (as of 2019-08-29) would be

[1, 2, 3].map { f(_1) }

You can read the feature request here; the follow-up discussion here is a more recent take on it.

like image 106
Amadan Avatar answered Dec 16 '25 18:12

Amadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!