Method: Kernel#deep_clone
- Defined in:
- lib/core/facets/kernel/deep_clone.rb
#deep_clone(cache = {}) ⇒ Object
Deep clone an object by deep cloning every instance variable as well.
Returns [Object]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/core/facets/kernel/deep_clone.rb', line 8 def deep_clone(cache={}) return cache[self] if cache.key?(self) copy = clone() cache[self] = copy copy.instance_variables.each do |var| val = instance_variable_get(var) begin val = val.deep_clone(cache) rescue TypeError next end copy.instance_variable_set(var, val) end return copy end |