The meaning of a = b in object oriented languages(ruby-talk)

ここの話が参考になった。内容をまとめると、こんな感じ。

#a,bに入れる値は元のものとは異なっています。
a = ["a", "b"]
b = a
a[0] = "z"
p a #=>["z", "b"]
p b #=>["z", "b"]

#一方で、
a = ["a", "b"]
b = a
a = ["aa"]
p a #=>["aa"]
p b #=>["a", "b"]

上の方により、「a=["a","b"]」を定義したときに、aは代入した配列自身を指すのではなく、その配列への参照を指すということが分かり。「a = b」としたときには、同じ配列への参照をa,bが持つということが分かる。
 下の方では、新しく配列["aa"]を定義したときには変数aの中に["aa"]という値が入るのではなく、変数a(の参照)が指し示す先が["a","b"]から["aa"]に変わる(bの指す参照は変わらない)ということが分かる。
Summercoolさん(最初に投稿した人)の発言の抜粋

i think:
whenever in Ruby, Python, and Java,
a is never an object. a is always a "reference to an object"... this
will solve a lot of puzzles when we don't understand some code
behaviors.


when a writing or a book reads "a is a Hash object; a is an Array
object; or a is an Animal object" it is just a short form to say that
"a is a reference to that object."
b = a means "whatever a is referencing to, now b is referencing it
too".
so that's why a[1] = "foobar" will change what b will display, but
a = "foobar" will not change what b will display. (because a[1] =
"foobar" says "what is a referencing? go there and change its
content that has the index 1" and when b goes there to see it, it is
also changed.)

英語だからと敬遠していたけど、読んでみると意外と意味が分かるし楽しい。 >ruby-talk
今度から暇になったら読んでみよう