Ruby/Array/shift

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

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

Using shift and unshift

# To remove an element from an array is with the shift method. 
# This method returns the first element of an array (nil if the array is empty), and then removes the element, shifting all other elements down by one. 
dates = [ 4, 5, 6, 7 ] # => [4, 5, 6, 7]
dates.shift # => 4
p dates # => [5, 6, 7]