Created
December 1, 2012 02:38
-
-
Save camdez/4180292 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
# Invoke each zero-arity method in messages on obj, returning the | |
# results of those calls in a Hash. | |
# | |
# messages - one or more symbols representing methods to invoke on | |
# obj. | |
# | |
# Examples | |
# | |
# "foo".multi_send(:length, :reverse) | |
# # => {:length=>3, :reverse=>"oof"} | |
# | |
# Returns a Hash containing each symbol in messages mapped to the | |
# value returned by invoking that method on obj. | |
def multi_send(*messages) | |
messages.inject({}) { |h, msg| h[msg] = send msg; h } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment