Hi --

On Sat, 6 Jan 2007, Shea Martin wrote:

> Consider a simple class like this:
> class MyClass
>  def initialize
>    @var1 = ''
>    @arr1 = []
>  end
> end
>
>
> Now if I have an instance of MyClass, and want to clone it, what is the 
> 'cleanest' way to do this?
>
> a = MyClass.new
> b = a.clone
>
> This method leaves 'b.arr1' pointing to the same data as a.arr1.

I don't see an a.arr1 method.  Did you mean to create some accessors
methods?

The most common idiom I've seen for deep copying is:

   b = Marshal.load(Marshal.dump(a))


David

-- 
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
    (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)