pop

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

Removes the last element from self and returns it, or nil if the array is empty.

If a number n is given, returns an array of the last n elements (or less) just like array.slice!(-n, n) does. See also #push for the opposite effect.

1
2
3
4
a = [ "a", "b", "c", "d" ]
a.pop     #=> "d"
a.pop(2#=> ["b", "c"]
a         #=> ["a"]
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.