M
Michael Artz
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
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