From: Hank Gong Date: 2005-12-21T20:40:00+09:00 Subject: A interesting obervation about object_id method ------=_Part_17665_17982672.1135165188394 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline #integer puts "For number" a=3D1 b=3Da puts a.object_id puts b.object_id b=3D2 puts b.object_id b=3D1 puts b.object_id >>For number >>3 >>3 >>5 >>3 #You can see that: # 1) for the same integer, the object_id is the same # 2) When b change, a will not change #string puts "For String" a=3D"Hello world!" b=3Da puts a.object_id puts b.object_id b=3D"Bye world!" puts b.object_id b=3D"Hello world!" puts b.object_id b=3D"Why?" puts b.object_id b=3D"Why?" puts b.object_id puts "Why?".object_id >>For String >>40660112 >>40660112 >>40660076 >>40660052 >>40660028 >>40660004 >>40659980 # 1) When you assign b=3Da, the object_id of b and a is same # 2) but when you change b's string, the b's object_id will change # 3) if you change b's string again, the b's object_id will also change puts "For Array" a=3D[1,2,3,4] b=3Da puts a.object_id puts b.object_id b[2]=3D100 puts b.object_id puts b.join(",") puts a.object_id puts a.join(",") >>For Array >>21563588 >>21563588 >>21563588 >>1,2,100,4 >>21563588 >>1,2,100,4 # 1) when b=3Da, the b and a will be the same object_id # 2) when you change b's elements, b's object_id will be same # 3) when you change b's elements, a will also be changed I think it's very interesting experiments. Hope someone can give us a clear explanation. -- Huazhi Gong (Hank) ------=_Part_17665_17982672.1135165188394--