Class: Array (Ruby 2.5.1)
unshift will add a new item to the beginning of an array. arr. unshift (0) #=> [0, 1, 2, 3, 4, 5, 6] With insert you can add a new element to an array at any position. arr. insert (3, 'apple') #=> [0, 1, 2, 'apple', 3, 4, 5, 6] Using the insert method, you can also insert.