3 ms·
This is why I love Ruby 2.7's numbered block parameters: https://rubyreferences.github.io/rubychanges/2.7.html#numbered-block-parameters https://rubyreferences.
by Lammy 2y ago
This is why I love Ruby 2.7's numbered block parameters: https://rubyreferences.github.io/rubychanges/2.7.html#numbered-block-parameters https://rubyreferences.github.io/rubychanges/2.7.html#number...
I've always hated the pattern where you have to declare a throwaway param name within a block for cases where the `::Symbol#to_proc` syntax won't work, like when the method you're trying to call needs some argument. They usually end up as nonsense single-characters anyway so they may as well just be numbers I don't have to think about!
irb(main):001> lol = [1337, 420, 69]
=> [1337, 420, 69]
irb(main):002> lol.map(&:to_s)
=> ["1337", "420", "69"]
irb(main):003> lol.map { |wow_this_sure_is_annoying| wow_this_sure_is_annoying.to_s(16) }
=> ["539", "1a4", "45"]
irb(main):004> lol.map { _1.to_s(16) }
=> ["539", "1a4", "45"]