[YANQ] -yet another (ruby) newbie question -string#concat

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 ? :slight_smile:

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 :slight_smile:

Gavin

Many thanks,
-botp

Hi –

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 ? :slight_smile:

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 :slight_smile:

<< 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

···

On Mon, 9 Dec 2002, [iso-8859-1] “Peña, Botp” wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav