| Short description: |
Clone object itself and it's inherited objects, too |
| Category: |
Library/Datastructure |
| Status: |
beta |
| Created: |
2006-05-25 18:41:13 GMT |
| Last update: |
2007-07-05 11:31:13 GMT |
| Owner: |
Jan Molič
(Projects of this owner) |
| Homepage: |
http://facets.rubyforge.org/ |
| Download: |
http://facets.rubyforge.org/
|
| License: |
Ruby's |
| Dependency: |
|
| Description: |
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
2.
require 'rubygems'
require 'deep_clone'
include DeepClone
obj = [] # []
a = [ true, false, obj ] # [true, false, []]
b = a.deep_clone # [true, false, []]
obj << 'foo' # ["foo"]
p obj # ["foo"]
p b[2] # []
|