Mega Code Archive

 
Categories / Ruby / Array
 

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]