|
|
|
|
|
by pmontra
2639 days ago
|
|
They both look ugly to me. Furthermore, there is a cognitive burden.
There is nothing to think about in users.map{|u| u.name}
I even use to write it more explicitly as users.map{|user| user.name}
The short forms users.map{&:name}
users.map{@1.name}
are like "oh wow, what does that mean?" and I've been using Ruby since 2005. And the ugliness... |
|
e.g.
or The only thing that &:symbol adds is that it defines to_proc on Symbols to create a Proc object that sends the symbol to it's first parameter, you could define it yourself if Ruby didn't already, and in fact it was first defined by users of Ruby before it became part of Ruby core.Definition:
This definition allows `["1", "2", 3].map(&:to_i)` to work in Ruby 1.8.6, which otherwise doesn't support it.