From: Chintan Trivedi Date: 2005-12-21T20:47:54+09:00 Subject: Re: A interesting obervation about object_id method --0-333106451-1135165662=:79062 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit puts "For String" a="Hello world!" b=a puts a.object_id puts b.object_id b="Bye world!" puts b.object_id The object id of b is changing bcz u are redifining b using "=" operator. Instead if u use b.replace("Bye word!") thn the object id will not change. Hank Gong wrote: #integer puts "For number" a=1 b=a puts a.object_id puts b.object_id b=2 puts b.object_id b=1 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="Hello world!" b=a puts a.object_id puts b.object_id b="Bye world!" puts b.object_id b="Hello world!" puts b.object_id b="Why?" puts b.object_id b="Why?" puts b.object_id puts "Why?".object_id >>For String >>40660112 >>40660112 >>40660076 >>40660052 >>40660028 >>40660004 >>40659980 # 1) When you assign b=a, 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=[1,2,3,4] b=a puts a.object_id puts b.object_id b[2]=100 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=a, 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) __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-333106451-1135165662=:79062--