method

shift

v1_8_6_287 - Show latest stable - Class: Array
shift()
public

Returns the first element of self and removes it (shifting all other elements down by one). Returns nil if the array is empty.

   args = [ "-m", "-q", "filename" ]
   args.shift   #=> "-m"
   args         #=> ["-q", "filename"]

1Note

Doesn't return nil on empty array when param is given

nhance ยท Apr 1, 20103 thanks

This does not return nil if the array is empty and n is given.

[].shift(2) # => []

a = []
a.shift(2) # => []
a # => []