Ruby | pop() function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The pop() function in Ruby is used to pop or remove the last element of the given array and returns the removed elements. Syntax: pop(Elements) Parameters: Elements : This is the number of elements which are to be removed from the end of the given array. If this parameter is not used then it removes and returns the single last element of the given array. Returns: the removed elements. Example 1: Ruby # Initializing some arrays of elements Array = [1, 2, 3, 4, 5, 6, 7] # Calling pop() function A = Array.pop B = Array.pop(2) C = Array.pop(3) D = Array # Printing the removed elements puts "#{A}" puts "#{B}" puts "#{C}" # Printing the remaining array puts "#{D}" Output: 7 [5, 6] [2, 3, 4] [1] Example 2: Ruby # Initializing some arrays of elements Array = ["a", "b", "c", "d", "e", "f", "g"] # Calling pop() function A = Array.pop B = Array.pop(1) C = Array.pop(2) D = Array.pop(3) E = Array # Printing the removed elements puts "#{A}" puts "#{B}" puts "#{C}" puts "#{D}" # Printing the remaining array puts "#{E}" Output: g ["f"] ["d", "e"] ["a", "b", "c"] [] Reference: https://devdocs.io/ruby~2.5/array#method-i-pop Comment More infoAdvertise with us Next Article Ruby | SizedQueue pop() function K Kanchan_Ray Follow Improve Article Tags : Ruby Ruby-Methods Similar Reads Ruby | push() function The push() function in Ruby is used to push the given element at the end of the given array and returns the array itself with the pushed elements. Syntax: push(Elements) Parameters: Elements : These are the elements which are to be added at the end of the given array. Returns: the array of pushed el 2 min read 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 # Ruby code for pop() method # declaring array a = [18, 22, 33, nil, 1 min read Ruby | Queue pop() function The pop() is an inbuilt function in Ruby returns the element in the front of the queue and removes it from the queue. Syntax: q_name.pop() Parameters: The function does not takes any element. Return Value: It returns the first element which is at the front of the queue and removes it from the queue. 1 min read Ruby | at() function The at() function in Ruby is used to return the element of the specified index. Index 0 is for the first element of the array, 1 for the second element of the array and so on. The negative index counts from the end of the input array. Syntax: Array.at(Index) Here Array is the input array of elements 2 min read Ruby | SizedQueue pop() function The pop() is an inbuilt function in Ruby returns the element in the front of the SizedQueue and removes it from the SizedQueue. Syntax: sq_name.pop() Parameters: The function does not takes any element. Return Value: It returns the first element which is at the front of the SizedQueue and removes it 1 min read Ruby | Array map() function Array#map() : map() is a Array class method which returns a new array containing the values returned by the block. Syntax: Array.map() Parameter: Array Return: a new array containing the values returned by the block. Example #1 : Ruby # Ruby code for map() method # declaring array a = [18, 22, 33, 3 2 min read Like