From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2001-12-19T23:46:30+09:00 Subject: [ruby-talk:28912] Re: clone objects In article , Le Wang wrote: >Hi, > >This has been discussed in other threads, but I still need one >concrete example of how one would clone an object's private fields >without exposing them (in other words, make them public) > >class A > def initialize (anArray) > @array = anArray > end >end > >How would I 'deep copy' this without making a public accessor to >array? > >Thanks >-lw try: class Object def deep_clone Marshal::load(Marshal.dump(self)) end end instanceOfA = A.new(['a','b','c']) anotherA = instanceOfA.deep_clone Phil