From: James Edward Gray II Date: 2005-06-18T08:58:34+09:00 Subject: Re: Why do arrays work this way? On Jun 17, 2005, at 6:51 PM, Nigel Wilkinson wrote: > Hi folks > > I'm using ruby 1.8.2 as comes with Mandriva 2005LE and get the > following behaviour with arrays which doesn't seem logical to me. [snip examples] > so what's the logic behind 'a' & 'c' changing when I change 'b'. > > Is this a bug? and if not what's the reasoning behind this > behaviour please. In Ruby, everything is an object, but variables are just references to those objects. Your `b=a` sets b to reference the same object as a. Thus, when you make a change to one, they all change. Now, if you used `b=a.dup` b would be set to reference a copy of a, and the changes would not filter over. Try playing around in irb as you have been doing, but calling object_id() on the arrays to seem which objects are the same. Hope that helps. James Edward Gray II