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!))
Posted by Tobias Kraze to makandra dev (2011-06-30 14:19)