From: Nikodemus Siivola Date: 2002-08-07T18:52:42+09:00 Subject: Re: Dup and Clone On Wed, 7 Aug 2002, Tom Gilbert wrote: > a = Marshal.restore(Marshal.dump(b)) a) It's ugly. b) Not everything can be marhalled anyway. IMHO, the right thing to do is to redefine clone for those classes that need special treatment. The object should know how to clone it self. Of course, something like the following would be nice the base distro. Notice how it just redefines clone, and also uses clone to copy it's instance variable as well -- so to be a true deep copy the instance variables have to include the DeepClone as well. Untested -- written from memory: module DeepClone alias clone shallow_clone def clone klone = self.shallow_clone self.instance_variables.each { |var| val = self.var.clone klone.__send__("#{var}=",val) } return klone end end -- Nikodemus ------------------------------------------------------------ I refuse to have a battle of wits with an unarmed person.