From: Yossef Mendelssohn Date: 2009-02-24T06:09:14+09:00 Subject: Re: pointer and other questions On Feb 23, 2:40 pm, Daniel Schoch 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.) 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' -- -yossef