Ruby | SizedQueue << function

The <<() is an inbuilt function in Ruby inserts the element in the SizedQueue. The SizedQueue have a particular capacity and cannot accept elements once it is full.

Syntax: sq_name << element

Parameters: The function takes the element to be inserted into the SizedQueue.



Return Value: It inserts the element into the SizedQueue.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for << function in SizedQueue
  
#Create a new SizedQUEUE q1
q1 = SizedQueue.new(2)
  
#push 5
         q1
     << 5
#push 6
     q1
     << 6
  
#Prints the element
        puts q1.pop
            puts q1.pop

chevron_right


Output:

5
6

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for << function in SizedQueue
  
#Create a new SizedQUEUE q1
q1 = SizedQueue.new(3)
  
#push 15
         q1
     << 15
  
#push 16
     q1
     << 16
  
#push 17
     q1
     << 17
  
#Prints the element
        puts q1.pop
            puts q1.pop
                puts q1.pop

chevron_right


Output:

15
16
17

Reference: https://devdocs.io/ruby~2.5/sizedqueue#method-i-3C-3C



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.