Skip to content

Instantly share code, notes, and snippets.

@camdez
Created December 1, 2012 02:38
Show Gist options
  • Save camdez/4180292 to your computer and use it in GitHub Desktop.
Save camdez/4180292 to your computer and use it in GitHub Desktop.
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