From: Martin DeMello Date: 2008-08-20T08:26:57+09:00 Subject: Re: Nested Arrays in Method Definitions--a puzzle On Tue, Aug 19, 2008 at 4:16 PM, Jonah Bloch-Johnson wrote: > > def haves > x = [1] > y = [] > y << x > x = [2] # (compare this) > y > end > > Why does meddling with the innards of the "x" have retroactive > repercussions, whereas redefining it outright does not? When you say 'x = [2]' you aren't redefining the object x, you are taking the variable 'x' and binding it to a new object. When you say y << x, you are inserting the object that x was pointing to at that moment into y, not the variable x. Think of a variable as an alias for an object - what is actually passed around are the objects themselves, but you can refer to them by any of their current aliases. martin