H
Hank Gong
------=_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
#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
# 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(",")
# 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.
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
#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
# 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(",")
# 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.