C
Chris Davies
Hi,
I'm currently trying to learn ruby, coming from a perl/unix
background. I've been working through one of the many online tutorials
and it's suddenly thrown in the "<<" operator.
Now, I'm familiar with a the use of "<<" as a bitwise left shift
and as a here doc, but this one throws me. The relevant URL is
http://rubylearning.com/satishtalim/mutable_and_immutable_objects.html
and here's a variation on the theme for illustrative purposes:
str = 'one'
str << 'two'
puts str # onetwo
It seems to me that << in this context is equivalent to +=, but I can't
find any documentation explaining /why/ this is the case, and why I
should use one in preference to the other. (Google really doesn't like
"<<".)
Any suggestions, please?
Cheers,
Chris
I'm currently trying to learn ruby, coming from a perl/unix
background. I've been working through one of the many online tutorials
and it's suddenly thrown in the "<<" operator.
Now, I'm familiar with a the use of "<<" as a bitwise left shift
and as a here doc, but this one throws me. The relevant URL is
http://rubylearning.com/satishtalim/mutable_and_immutable_objects.html
and here's a variation on the theme for illustrative purposes:
str = 'one'
str << 'two'
puts str # onetwo
It seems to me that << in this context is equivalent to +=, but I can't
find any documentation explaining /why/ this is the case, and why I
should use one in preference to the other. (Google really doesn't like
"<<".)
Any suggestions, please?
Cheers,
Chris