From examining the documentation for Ruby 1.9.3, both Array#<< and Array#push were designed to implement appending an element to the end of the current array. However, there seem to be subtle differences between the two.
The one I have encountered is that the * operator can be used to append the contents of an entire other array to the current one, but only with #push.
a = [1,2,3]
b = [4,5,6]
a.push *b
=> [1,2,3,4,5,6]
Attempting to use #<< instead gives various errors, depending on whether it's used with the dot operator and/or parentheses.
Why does #<< not work the same way #push does? Is one not actually an alias for the other?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…