From: Harry Kakueki Date: 2007-06-06T00:22:16+09:00 Subject: Re: Deep Copy On 6/5/07, Michael Artz wrote: > I'm needing to implement a deep copy operation on a couple of objects, > and was wondering if there was a "best practices" for this sort of > thing. I've seen the Marshal.load(Marshal.dump()) idiom, but I'm using > singleton classes which can't be dumped. So I'm implementing my deep > copy similar to: > > def deep_copy > other = self.clone > other.instance_var_1 = self.instance_var_1.clone > other.instance_var_2 = self.instance_var_2.deep_copy > other > end > > where some of the instance variables are objects for which I've written > a deep_copy method. > > The biggest problem with this method (that I can see), is that all of > the attributes of the object need to be publically writable, which is > undesirable. Is there a better way to do this sort of thing? > > Thanks, > -Mike > > -- > Posted via http://www.ruby-forum.com/. > > I haven't used this and I'm not sure this is what you want but a deep copy post recently went through Ruby List. Take a look. http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/43424 http://d.hatena.ne.jp/pegacorn/20070412/1176309956 Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/