||Clone object itself and it's inherited objects, too
||2006-05-25 18:41:13 GMT
||2007-07-05 11:31:13 GMT
(Projects of this owner)
Adds deep_clone method to an object which produces deep copy of it. It means if you clone a Hash, every nested items and their nested items will be cloned. Moreover deep_clone checks if the object is already cloned to prevent endless recursion.
If you copy object using Marshal::load(Marshal::dump(obj)), error happen on undumpable objects (for example IO). Not when using deep_clone.
DeepClone is now a part of Ruby Facets - excelent library collection (you have to try ;-))
1. gem install facets
obj =  # 
a = [ true, false, obj ] # [true, false, ]
b = a.deep_clone # [true, false, ]
obj << 'foo' # ["foo"]
p obj # ["foo"]
p b #