On Jan 5, 2007, at 4:40 PM, Shea Martin wrote:
> Hmmm... I'll try overriding clone, and manually deal with the arrays:
>
> There has to be a simple way to do something like this?  What is  
> common recipe for something like this?   Should this really be that  
> hard in ruby?

Warning: I didn't test these...

   def clone
     rslt = super	# Use the default #clone instead of Myclass.new

     instance_variables.each do |member|
       rslt.instance_variable_set( member, instance_variable_get 
(member).clone )
     end

     rslt
   end

For your particular case you could avoid the loop of course:

   def clone
     rslt = super
     rslt.instance_variable_set "@var1", @var1.clone
     rslt.instance_variable_set "@arr1", @arr1.clone
     rslt
   end



Gary Wright