From: William Djaja Tjokroaminata Date: 2002-10-24T01:00:07+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) Hi, As already been pointed out, this is because in Ruby when a variable is assigned to another variable, the new variable simply refers to the same object that the old variable refers to: a = AnObject.new b = a # b really refers to the same, identical AnObject as a Therefore, if '+=' means 'append()', then what you will have is b += anotherObj # a will also be a = a.append(anotherObj) The only safe/natural way of having '+=' to mean 'append()' is by changing the semantic in Ruby by having the variable assignment operator to invoke some copy method: # Not a Ruby code a = AnObject.new b = a # b = a.copy() b += anotherObj # b = b.append(anotherObj), a unchanged But Ruby does not work that way; you have to use C++ if that is really the intention. Regards, Bill ========================================================================= "Mills Thomas (app1tam)" wrote: > But why does it really, REALLY mean that? Was there a reason for doing > this? Is it non-trivial to have '+=' mean 'append()'? > Drew >> -----Original Message----- >> From: Hal E. Fulton [mailto:hal9000@hypermetrics.com] >> Sent: Monday, October 21, 2002 11:18 PM >> To: ruby-talk@ruby-lang.org >> Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) >> >> >> It's a feature. :) The notation a+=b really, REALLY >> means a = a + b. There is a + operator, but never a >> += operator, in Ruby (or any other assignment). >> >> Hal >> >>