From: "Jesús Gabriel y Galán" Date: 2010-04-02T18:24:20+09:00 Subject: Re: scope question On Fri, Apr 2, 2010 at 10:25 AM, Harry Kakueki wrote: >> >> a_hash, an_arr and a_num are local to the method indeed. However, a_hash and an_array hold references to hash and array > object respectively, not copies. So you are changing the objects passed to this method via those references. On the other hand, > a_num is passed a Fixnum instance which are implemented as immediate objects and hence passed as copy. >> > > def scope_q(an_arr) >  #an_arr[1] = 5  #This is a reference. >  an_arr = [6,6] #This is a local an_arr ? > end > > a = [1,2,3,4] > > scope_q(a) > > p a  #> [1, 2, 3, 4] To clarify this: variables are references to objects. When you say this: an_array[1]= 5 you are calling method "[]=" of the object referenced by an_array. This object happens to be referenced also in the outer scope of the method scope_q, in your example by variable a. So, if the method "[]=" modifies the object, that modification is seen outside when you reference the object with variable a. On the other hand, when you do this: an_arr = [6,6] you are not calling any method on the object previously referenced by an_arr. You are assigning a new object to the local variable an_arr. This does not affect in any way variable "a" in the outer scope, or the object referenced by a. Jesus.