instance method
deep_dup
Ruby on Rails 7.2.3
Since v3.1.12Signature
deep_dup()
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"
Source
# File activesupport/lib/active_support/core_ext/object/deep_dup.rb, line 43
def deep_dup
hash = dup
each_pair do |key, value|
if ::String === key || ::Symbol === key
hash[key] = value.deep_dup
else
hash.delete(key)
hash[key.deep_dup] = value.deep_dup
end
end
hash
end
Defined in activesupport/lib/active_support/core_ext/object/deep_dup.rb line 43
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Hash