Created
October 29, 2013 08:10
-
-
Save makefunstuff/7210734 to your computer and use it in GitHub Desktop.
deep_merge
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
# Merges self with another hash, recursively. | |
# | |
# This code was lovingly stolen from some random gem: | |
# http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html | |
# | |
# Thanks to whoever made it. | |
def deep_merge(hash) | |
target = dup | |
hash.keys.each do |key| | |
if hash[key].is_a? Hash and self[key].is_a? Hash | |
target[key] = target[key].deep_merge(hash[key]) | |
next | |
end | |
target[key] = hash[key] | |
end | |
target | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment