From: Ruby Student Date: 2008-10-05T20:26:01+09:00 Subject: Re: question regarding sub!() ------=_Part_62486_21244969.1223206062824 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Sun, Oct 5, 2008 at 6:37 AM, Lex Williams wrote: > when writing : > > string2 = string1 > > both your variables reference the same address , so , modifications to > any of them will cause modification to the other . > > If you write : > > string2 = string1.clone > > then you will modify just string2 , when writing sub! > -- > Posted via http://www.ruby-forum.com/. > > But, why then, the following is not true??? n1 = 100 n2 = n2 To this point the are the same, including the object_id. But when I assign: n2 = 200 The n1 does not change and the object_id of n2 change. Please see the irb session below. irb irb(main):001:0> n1 = 100 => 100 irb(main):002:0> n2 = n1 => 100 irb(main):003:0> p n1 100 => nil irb(main):004:0> p n2 100 => nil irb(main):005:0> p n1.object_id 201 => nil irb(main):006:0> p n2_object_id NameError: undefined local variable or method `n2_object_id' for main:Object from (irb):6 from :0 irb(main):007:0> p n2.object_id 201 => nil irb(main):008:0> n2 = 200 => 200 irb(main):009:0> p n1 100 => nil irb(main):010:0> p n2 200 => nil irb(main):011:0> p n1.object_id 201 => nil irb(main):013:0> p n2.object_id 401 => nil irb(main):014:0> Thank you Ruby Student ------=_Part_62486_21244969.1223206062824--