[Rails] Deep Copy Method?

Eric Hodel drbrain at segment7.net
Tue Jan 4 00:20:14 GMT 2005


On 03 Jan 2005, at 12:44, Thomas Counsell wrote:

> Have you got a / can you help with a generic method for doing a deep 
> copy of a set of Rails objects?
>
> I see there is a clone method for individual objects.
>
> I can also see it would be pretty easy to implement a method that 
> copies down a tree.
>
> The tricky bit is how to deep copy where objects within the tree 
> reference each other?
>
> Thanks for any tips.

class Object
   def deep_clone
     Marshal.load Marshal.dump(self)
   end
end

-- 
Eric Hodel - drbrain at segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E  7C11 332A 551C 796C 9F04
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://one.textdrive.com/pipermail/rails/attachments/20050103/b9e75afb/PGP.bin


More information about the Rails mailing list