From: Gennady Bystritsky Date: 2008-04-16T00:42:32+09:00 Subject: Re: How to duplicate a object changing the class without attributes memory copy Iņaki Baz Castillo wrote: > 2008/4/15, Gennady Bystritsky : >> Not true. To verify it, after you do "from.name = header.name", try >> this: >> >> puts header.name.object_id >> puts from.name.object_id >> >> You will see same object id, meaning that you have a reference, not >> a new object. > > Ohh, that's annoying for me! > You are right, both are the same objects **until** I modify > one of them. I mean: > > from.name = header.name > => "AAAA" > from.name. object_id == header.name.object_id > => true > > So in this moment from.name. object_id == header.name.object_id. But > if I change the value: > > from.name = "BBBB" > from.name. object_id == header.name.object_id > => false > > Then from.name. object_id != header.name.object_id, so then there are > two values in memory at same time. > > Regards. You do not change the value, you just assign a reference to a new string. To change the content of a string object you need to use replace() on it. It looks like it omits you that "AAAA" and "BBBB" make string objects already and not just when you assign them to a variable. Gennady.