From: Raphael Bauduin Date: 2004-03-15T19:44:38+09:00 Subject: Re: Object#clone and Object#dup I use the suggested Marshall way: Marshal::load(Marshal::dump(self)) and it's working as I wanted. Thanks for the help! Raph Raphael Bauduin wrote: > Hi, > > I'd like to duplicate n object, work on the copy, and be sure the original > isn't change at all. How can I do that? > > From the pickaxe (example similar to what I'm working on): > > class Klass > attr_accessor :str > end > > s1 = Klass.new > => # > s1.str = "Hello" > => "Hello" > s2 = s1.dup > => # > s2.str[1,4] = "i" > => "i" > > s1.str > => "Hi" > > s2.str > => "Hi" > > I would like that s1.str still returns "Hello". I tried with dup and clone, > with the same result.... What method should I use? > > Thanks > > Raph