Created
March 14, 2010 02:46
-
-
Save ordinaryzelig/331733 to your computer and use it in GitHub Desktop.
attributes hash for any object
This file contains 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
# convert results of calling methods into attributes hash. | |
# e.g. Date.today.attributes_for(:day, :month, :year) would return | |
# {:day => 13, :month => 3, :year => 2010} | |
class Object | |
def attributes_for(*method_names) | |
method_names.inject({}) do |hash, method_name| | |
hash[method_name] = send(method_name) | |
hash | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment