Array#shift removes and returns the first element of an array. The array changes permanently, and the remaining elements move toward index zero. Passing an integer removes that many elements and returns them as an array. section 9.2.2
Removing from the beginning
a = [1, 2, 3, 4, 5] a.shift # => 1 a # => [2, 3, 4, 5] a.shift(2) # => [2, 3] a # => [4, 5] Use pop for the corresponding operation at the end of the array. section 9.2.2
Because shift mutates its argument, using it inside a method can consume the caller’s array. Repeated calls may therefore produce different results; Enumerable#reduce offers a side-effect-free alternative for summing elements. section 16.1.1
