Clarification on the Ruby << Operator

前端 未结 5 1359
春和景丽
春和景丽 2021-01-11 09:22

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

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 10:10

    The << function, according to http://ruby-doc.org/core-1.9.3/Array.html#method-i-3C-3C, is an append function. It appends the passed-in value to the array and then returns the array itself. Ruby objects can often have functions defined on them that, in other languages, would look like an operator.

提交回复
热议问题