Class: Hash
Instance Method Summary collapse
-
#deep_dup ⇒ Object
Returns a deep copy of hash.
Instance Method Details
#deep_dup ⇒ Object
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"
41 42 43 44 45 |
# File 'lib/chewy/backports/deep_dup.rb', line 41 def deep_dup each_with_object(dup) do |(key, value), hash| hash[key.deep_dup] = value.deep_dup end end |