Created
December 9, 2011 00:20
-
-
Save yaronw/1449411 to your computer and use it in GitHub Desktop.
Ruby Hash Merge Function for Multiple Hashes
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
# A little function to easily merge multiple hashes. | |
# Example: Given h1, ..., h4 are hashes, | |
# hash_merge(h1, h2, h3, h4) | |
# or | |
# hash_merge *[h1, h2, h3, h4] | |
# | |
# More on this function and the Ruby syntax presented here at | |
# http://yaronwalfish.com/ruby-hash-merge-function-for-multiple-hashes-inject-and-asterisk-notation/ | |
def hash_merge *hashes | |
hashes.inject :merge | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment