shift

ary.shift â obj or nil
ary.shift(n) â new_ary
Instance Public methods

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

If a number n is given, returns an array of the first n elements (or less) just like array.slice!(0, n) does. With ary containing only the remainder elements, not including what was shifted to new_ary. See also #unshift for the opposite effect.

1
2
3
4
5
6
7
args = [ "-m", "-q", "filename" ]
args.shift     #=> "-m"
args           #=> ["-q", "filename"]
 
args = [ "-m", "-q", "filename" ]
args.shift(2#=> ["-m", "-q"]
args           #=> ["filename"]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.