From: Ian Macdonald Date: 2002-10-22T12:03:21+09:00 Subject: Re: Things That Newcomers to Ruby Should Know (10/16/02) On Sat 19 Oct 2002 at 00:42:20 +0900, Kontra, Gergely wrote: > > 13. Ruby variables hold references to objects and the = operator > > copies the references. Also, a self assignment such as a += b is > > actually translated to a = a + b. Therefore it may be advisable to > > be aware whether in a certain operation you are actually creating > > a new object or modifying an existing one. > > > a. In Ruby the "self assignment operator" goes beyond "+=, -=, *=, > > /=, %=". In particular, operators such as "||=" also exist (but > > currently not for a class variable if it is not yet defined; this > > may change in the future). Please see Table 18.4 in the > > "Programming Ruby" book for the complete list. > > Also notice (performance tip), that > string << "another" is much faster than string+="another" (no extra > object creation) > so you should use any class-defined update-method, if exists. Hmm, why does 'string += another' need to create a new object? string already exists, so wouldn't the reference simply be updated? Ian -- Ian Macdonald | Q: What do you call a monk who has had a ian@caliban.org | sex change operation? A: A transsister. | | |