On 23.02.2009 22:09, Yossef Mendelssohn wrote: > On Feb 23, 2:40 pm, Daniel Schoch <tr... / tekwissusa.com> wrote: >> I also found this comment in one of the ruby getting started texts. >> >>> Ruby variables hold references to objects and the = operator copies >>> references. >> Now what about this ? >> b = 1 >> a = b >> b = 2 >> Shouldn't 'a' now contain 2 if the above statement is true? Clearly not >> every variable is a reference. > > This isn't entirely the same with numbers as with many other Ruby data > types because Fixnum is immediate. (There's only one instance of 1.) This is irrelevant from a user's point of view. The logic stays the same: b = 1 # or any other object! a = b # a now points to the same object, 1 in this case b = 2 # or any other object! a still points to 1 while b points to 2 Even though it's technical different under the hood - Fixnums blend totally with other objects with regard to reference handling. > But to show the same example using a different datatype: > > b = 'hi' # b is now a reference to a variable containing the string > 'hi' > a = b # a and b now reference the same variable. Changing one > (using sub! or similar) will change both > b = 'hello' # b is now a reference to a different variable containing > the string 'hello', a is still the old reference to 'hi' As you demonstrated - it's all the same. Cheers robert