Ruby | Array pop() function
Array#pop() : pop() is a Array class method which checks removes the last element from the array and returns it.
Syntax: Array.pop()
Parameter: Array
Return: removes the last element from the array and returns it.
Example #1 :
# Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [34, 5, 7] # pop method example puts "pop() method form : #{a.pop()}\n\n" puts "pop() method form : #{b.pop()}\n\n" puts "pop() method form : #{c.pop(2)}\n\n" |
chevron_right
filter_none
Output :
pop() method form : 6 pop() method form : 9 pop() method form : [5, 7]
Example #2 :
# Ruby code for pop() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = [nil, "abc", "nil", "dog"] # declaring array b = ["cow", nil, "dog"] # pop method example puts "pop() method form : #{a.pop(2)}\n\n" puts "pop() method form : #{b.pop(1)}\n\n" puts "pop() method form : #{c.pop(0)}\n\n" |
chevron_right
filter_none
Output :
pop() method form : ["nil", "dog"] pop() method form : ["dog"] pop() method form : []
Recommended Posts:
- Ruby | Array map() function
- Ruby Array () function with example
- Ruby | Array take() function
- Ruby | Array none?() function
- Ruby | Array min() function
- Ruby | Array max() function
- Ruby | Array zip() function
- Ruby | Array one?() function
- Ruby | Array &() function
- Ruby | Array <=> function
- Ruby | Array slice!() function
- Ruby | Array class last() function
- Ruby | Array Concatenation using (+) function
- Ruby | Array length() function
- Ruby | Array slice() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



