Now that Ruby has numbered block arguments are there any technical reasons why the use of symbol to proc would be still preferred?

Viewed 65

Updated title of the question to reflect was I was asking in content

I did not and do not intend this to be an opinion based question, I really want to know if there is some performance difference or memory usage difference that I should consider. The idiom of using "symbol to proc" may remain, I just want to know if there is a technical advantage to using it.


Before Ruby 2.7 the use of "symbol to proc" was the preferred way to handle single method calls in blocks.

For example I think this is preferred:

["1", "2", "3"].map(&:to_i)

over this:

["1", "2", "3"].map {|i| i.to_i}

But since the introduction of numbered block arguments in Ruby 2.7 I have begun using this:

["1", "2", "3"].map {_1.to_i}

Its just as concise but also seems more consistent all the other cases were a block is needed.

Are there any reasons, other than backwards compatibility, such as performance, to chose one over the other?

0 Answers
Related