From: Gary Wright Date: 2007-09-28T04:01:03+09:00 Subject: Re: Ruby's a = b vs PHP5's $obj1 =& $obj2 On Sep 27, 2007, at 10:34 AM, Jonas Roberto de Goes Filho (sysdebug) wrote: > PHP, $obj1 = & $obj2 means that both $obj1 and $obj2 points to the > same content. Its like hardlinks in Unix. > > In Ruby, depends of type of variable. If type of variable as > object, its work like as PHP. If type of variable as a number, its > not work as PHP. There is no need to think of 'numbers' as a special case in Ruby. And I don't think your example even illustrates that they are different. > sysdebug(main):031:0> num1 = 1 # num1 references the object > '1' > => 1 > sysdebug(main):032:0> num2 = num1 # num2 references the object > '1' > => 1 > sysdebug(main):033:0> num2 > => 1 > sysdebug(main):034:0> num1 = 2 # change num1 to reference > the object '2' > => 2 > sysdebug(main):035:0> num2 # num2 still references the > object '1' > => 1 > sysdebug(main):036:0> The trick is to think of integer literals not as values but as references to objects. 1 is not the "value" 1 but is a reference to the Fixnum object that behaves like the number 1 and there is only a single Fixnum object that behaves that way (i.e. Fixnum objects are *not* containers for integer values). Note: Not everyone thinks of Ruby integer's in this way but IMHO it makes Ruby's assignment semantics very simple and regular. Gary Wright