Hi --

On Thu, 24 Oct 2002, William Djaja Tjokroaminata wrote:

> Hi,
>
> Actually Ruby still gives you a choice.  When you have
>
>     a = AnObject.new
>     b = a
>
> If you don't want side effects, you simply type
>
>     b += anotherObj
>
> and if you want side effects, you may type
>
>     b << anotherObj    # if the '<<' operator is defined for AnObject

True, although the term "side effects" might be ascribing more
weirdness to it than there really is :-)  Anyway, another possible
factor here is that the += idiom harbors a potential snag that I don't
think has been mentioned in this thread (though it has been the
subject of threads), namely the conversion of the result to the class
of the argument.  For example:

  class S < String
    def speak
      puts "Hello, I contain: #{self}"
    end
  end

  a = S.new("one")
  b = a

  a.speak       # Hello, I contain: one

  a += " two"

  b.speak       # Hello, I contain: one
  a.speak       # NameError: no such method (a is now a String)


David

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