From: Hugh Sasse Staff Elec Eng Date: 2000-06-19T17:13:40+01:00 Subject: [ruby-talk:03520] Re: Deep copy? On Tue, 20 Jun 2000, GOTO Kentaro wrote: > In message "[ruby-talk:03516] Deep copy?" > on 00/06/19, Hugh Sasse Staff Elec Eng writes: > >Given that I cannot overload =, how should I go about ensuring a deep > >copy of an object, as opposed to a shallow copy? > > I think there isn't general way. The meaning of deep copy depends on > target object, so we have define such method for each class. OK. I can live with that I suppose. > > Marshal.dump is another option, but not perfect. > > class Object > def deep_copy > Marshal.load(Marshal.dump(self)) > end > end > > Maybe, deep copy is not suitable operation for an object. The only case I can think of is a self referencing object, but that is a special case for other things (like garbage collection?) too. > > -- gotoken > > Hugh