Mega Code Archive

 
Categories / Ruby / Array
 

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