I am quite new to Ruby and am wondering about the <<
operator. When I googled this operator, it says that it is a Binary Left Shift Operator given this ex
In Ruby, operators are just methods. Depending on the class of your variable, <<
can do different things:
# For integers it means bitwise left shift:
5 << 1 # gives 10
17 << 3 # gives 136
# arrays and strings, it means append:
"hello, " << "world" # gives "hello, world"
[1, 2, 3] << 4 # gives [1, 2, 3, 4]
It all depends on what the class defines <<
to be.