Ruby/Array/unshift

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

unshift prepends objects (one or more) to an array.

# It is like push but works on the beginning of an array, not the end.
dates = [ 4, 5, 6, 7 ] # => [4, 5, 6, 7]
dates.unshift 4 # => [4, 5, 6, 7]
dates.unshift(2,3) # => [2, 3, 4, 5, 6, 7]
puts dates