I thought operator overloading was a non-oop way of specifying  
multiple functions that each take different argument numbers? That's  
not what's going on here. This is messages having the same name  
exactly being sent to different classes having slightly different  
meanings depending on the class of the receiver. It's encapsulation,  
really... Each class encapsulates its meanings and can obviously have  
different meanings for the same method names depending on the classes  
in question.

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

On 14/02/2009, at 1:16 AM, Dido Sevilla <dido.sevilla / gmail.com> wrote:

> Ruby is capable of doing operator overloading, and the << operator has
> been consistently overloaded to do stuff like appending data (I
> believe this was an idea that came from C++). Note also that use of <<
> on strings is much faster than +=, since += will create a new string,
> append the string you're adding to it, and replace the old string by
> the new one, while, if I'm not mistaken << will append the data on its
> right side in place, if I recall correctly.
>
> Several other classes also overload the << operator. Using << on an
> array will append the right hand side to the end of the array
> (equivalent to Array#push). << on an IO object will write the object
> on the right hand side, converting it to a string, just as someone
> coming from C++ might expect.
>
> -- 
> 普通じゃないのが当然なら答える私は何ができる?
> 普通でも普通じゃなくて感じるまま感じることだけをするよ!
> http://stormwyrm.blogspot.com
>