Skip to content

Instantly share code, notes, and snippets.

@wuhuizuo
Created April 19, 2014 15:10
Show Gist options
  • Save wuhuizuo/11087142 to your computer and use it in GitHub Desktop.
Save wuhuizuo/11087142 to your computer and use it in GitHub Desktop.
Hash的深层merge
class Hash
def deep_merge!(other_hash)
other_hash.each_pair do |k, v|
tv = self[k]
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
end
self
end
def deep_merge(other_hash)
dup.deep_merge!(other_hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment