class Hash
def deep_dup
hash[:a][:c] #=> nil
dup[:a][:c] = 'c'
dup = hash.deep_dup
hash = { a: { b: 'b' } }
Returns a deep copy of hash.
def deep_dup each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end
def deep_dup each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end