Hi --

On Thu, 26 Sep 2002, J.Leuzinger wrote:

> Hi,
> Although a newbie, I am really impressed of this powerful and consistent
> language !

Welcome, nuby!

> Accidently I used the << operator instead of the + operator to concatenate
> two strings.
> The result was a bit surprising (but intelligibly if one uses the wrong
> method).
> What bothers me is that Ruby does not issue a warning when a Const String is
> modified by the << operator.
> If I use the += operator I get a warning.
> This seems to me a breach in terms of least surprise.
> Do I overlook something ?

It's because << adds to the existing String object, while +=
creates a new object.

  str += "abc"

is equivalent to

  str = str + "abc"

(new assignment)

So with << you're not re-initializing the constant, just changing it.


David

-- 
David Alan Black                      | Register for RubyConf 2002!
home: dblack / candle.superlink.net     | November 1-3
work: blackdav / shu.edu                | Seattle, WA, USA
Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com