Ruby | SizedQueue shift() function Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The shift() is an inbuilt function in Ruby returns the element in the front of the SizedQueue and removes it from the SizedQueue. Syntax: sq_name.shift() 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 from the SizedQueue. Example 1: CPP #Ruby program for shift() function in SizedQueue #Create a new SizedQueue q1 sq1 = SizedQueue.new(2) #push 5 sq1.push(5) #push 6 sq1.push(6) #Prints the top - most element and also shifts it puts sq1.shift puts q1.shift Output: 5 6 Example 2: CPP #Ruby program for shift function in SizedQueue #Create a new SizedQueue q1 sq1 = SizedQueue.new(2) #push 12 sq1.push(12) #push 21 sq1.push(21) #Prints the top - most element and also shifts it puts sq1.shift puts sq1.shift Output: 12 21 Reference: https://devdocs.io/ruby~2.5/SizedQueue#method-i-shift Comment More infoAdvertise with us Next Article Ruby | SizedQueue size() function G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Collections Ruby SizedQueue-class Similar Reads Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue size() function The size() is an inbuilt function in Ruby returns the current size of the SizedQueue or the number of objects present in it. Syntax: sq_name.size() Parameters: The function does not takes any parameter. Return Value: It returns the number of elements in the SizedQueue. Example 1: CPP #Ruby program f 1 min read Ruby | SizedQueue enq() function The enq() is an inbuilt function in Ruby inserts the element in the SizedQueue till it does not reaches its maximum capacity. Syntax: sq_name.enq(element) Parameters: The function takes the element to be inserted into the SizedQueue. Return Value: It inserts the element into the SizedQueue till it d 1 min read Ruby | SizedQueue enq() function The enq() is an inbuilt function in Ruby inserts the element in the SizedQueue till it does not reaches its maximum capacity. Syntax: sq_name.enq(element) Parameters: The function takes the element to be inserted into the SizedQueue. Return Value: It inserts the element into the SizedQueue till it d 1 min read Like