Class: Hash

Inherits:
Object show all
Defined in:
lib/backports/active_support/deep_dup.rb

Instance Method Summary collapse

Instance Method Details

#deep_dupObject

Returns a deep copy of hash.

hash = { a: { b: 'b' } } dup = hash.deep_dup dup[:a][:c] = 'c'

hash[:a][:c] #=> nil dup[:a][:c] #=> "c"


44
45
46
47
48
# File 'lib/backports/active_support/deep_dup.rb', line 44

def deep_dup
  each_with_object(dup) do |(key, value), hash|
    hash[key.deep_dup] = value.deep_dup
  end
end