When I collect values from an array, I like using this ruby idiom:
users.collect &:email
But then when I want to join those values, I end up having to expand it like so:
users.collect { |user| user.email }.join(", ")
Is there a better way to do this?
I don’t see why you have to expand it. You can do this:
The
&operator in this context is aSymbol#to_proc. It basically treats the symbol you supply as a method name that it should call on a receiver and return its result.