Skip to content

Instantly share code, notes, and snippets.

@yaronw
Created December 9, 2011 00:20
Show Gist options
  • Save yaronw/1449411 to your computer and use it in GitHub Desktop.
Save yaronw/1449411 to your computer and use it in GitHub Desktop.
Ruby Hash Merge Function for Multiple Hashes
# 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