> -----Original Message-----
> From: list-bounce / example.com 
> [mailto:list-bounce / example.com] On Behalf Of Russell Fulton
> Sent: Monday, August 14, 2006 7:37 PM
> To: ruby-talk ML
> Subject: Re: problems with dup and clone...
> 
> Russell Fulton wrote:
> >
> > I have tried both dup and clone to copy the default objects 
> but I always 
> > seem to end up with the original object in host.
> > 
> 
> More investigations reveals that the objects are being at least 
> partially copied. 'simple' variables (strings etc) are copied 
> by arrays 
> are not.
> 
> I have managed to work around this by adding a method fix to 
> the class 
> which reinitalised the instance arrays to [] and fix'ing the newly 
> dup'ed instances.
> 
> This appears to be a bug in ruby.  I'll see if I can 
> reproduce it in a 
> small program.

As several people have already indicated, Ruby's clone() and dup()
perform "shallow copy" by design. To achieve deep copy you can use
Marshal:

deep_cloned_object = Marshal.load(Marshal.dump(object))

Alternatively, you can use YAML instead of Marshal. Its serialized
output is human readable.

Best,
Gennady.

> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
>