Flowdock
method

deep_dup

Importance_1
Ruby on Rails latest stable (v4.0.2) - 1 note - Class: Hash
deep_dup() public

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"
Show source
Register or log in to add new notes.
August 25, 2014 - (v3.1.0 - v3.2.13)
0 thanks

This method does not correctly dup arrays

Watch out because this method does not correctly dup arrays values.

The bug can be reproduced with the following code:

hash = { 'a' => [1,2,3,4] }
dup  = hash.deep_dup
dup['a'].object_id == hash['a'].object_id # should return true

Rails 4 version does not have this issue because it is completely different implementation.