From: "Iñaki Baz Castillo" Date: 2008-04-25T01:55:30+09:00 Subject: Re: Pointer concept in Ruby ? 2008/4/24, khaines@enigo.com : > They were the same object, until you pointed a1 at a different object. > > This is the important distinction that you are missing. > > To recap: > > a = [1,2,3,4] > > a points to an Array that contains 4 objects, the Fixnums 1, 2, 3, and 4. > > a[1] calls a method [] on the object pointed to by 'a'. That method > returns the object in the 1 position in the array. > > a1 = a[1] points 'a1' at that object. a1 is just a pointer, though, to an > object. > > You can't change what the Array pointed to by 'a' contains by pointing 'a1' > at a different object, which is what your assignment of "NEW STRING" to 'a1' > did. > > If you want to change what is stored in the 1 index position in the Array > pointed to by 'a', you need to be operating on that Array. > > b = a > b[1] = "another new string" > puts a[1] > > another new string > > > Make sense? Sure, but I already kwen it, note that I was answering to Mikael that said: > If you however call a self-modifying method on a1 while it's pointing at the array string, it'll also > change in the array, as it's still pointing at the same object. But thanks for the explanation :) -- Iñaki Baz Castillo