Hack of the day: A reverse for Rails' &:

Ever wondered if there is a reverse for Rails' .each(&:to_s) idiom? Turns out there is...

You probably already know, that you can abbreviate code like

dogs.each { |dog| dog.bark! }

with

dogs.each(&:bark!)

Now suppose it is the other way round and you have

bones.each { |bone| dog.eat!(bone) }

Good old Ruby already has a solution:

bones.each(&dog.method(:eat!))
Tobias Kraze