Array#unshift adds one or more objects to the beginning of an array, shifting existing elements toward higher indexes. section 9.2.2
Add an element first
a = [1, 2, 3, 4] a.unshift(0) # a is now [0, 1, 2, 3, 4] section 9.2.2
Compare the methods used at array boundaries:
- Use unshift to add at the beginning. section 9.2.2
- Use push or << to add at the end; push accepts multiple arguments, while << adds one object. section 9.2.2
