From: dblack@... Date: 2002-12-09T13:11:07+09:00 Subject: Re: [YANQ] -yet another (ruby) newbie question -string#concat Hi -- On Mon, 9 Dec 2002, [iso-8859-1] "Pe�a, Botp" wrote: > Hi sir Gavin (aka Gavin Sinclair [mailto:gsinclair@soyabean.com.au]): > > You remarked last Monday, December 09, 2002 11:31 AM: > > > > > I wonder how much existing code such a change will break. > > After all, > > > who, in > > a > > > published program or library, would use #concat ? :) > > > > > > I meant "... such a change *would* break ...". I don't > > expect it to be changed any time soon. > > deprecating concat is even fine with me (my opinion only -but if it will be > changed, why not?). From now on, I'll be using "+" and "=" to achieve same > effect (and may << soon). Less confusion, less worry, works all the time :-) << is good, and has that nice palpable feel of sticking something on the end of the string. Beware of +=. It doesn't achieve the same effect. You end up with a different object, which might be a problem, depending what else is going on. One potential problem is the oft-mentioned: class S < String def talk; puts "I consist of #{self}"; end end s = S.new("hello") s.talk # I consist of hello s += " there" s.talk # undefined method! which happens because the + operation returns a String object, not an S object. If you do s << " there" instead, you keep the same object and it continues to respond to 'talk'. (See the archives... this is another one on which there's been a lot of past discussion.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav