Ruby | SizedQueue empty? function

The empty? is an inbuilt function in Ruby checks if the SizedQueue is empty or not?. It returns a boolean value, which is true if the SizedQueue is empty or it returns false. Empty here means if it contains elements or not in it.

Syntax: sq_name.empty?

Parameters: The function does not takes any element.

Return Value: It returns true if the SizedQueue is empty else it returns false.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for empty ? function in SizedQueue
  
#Create a new SizedQueue q1
sq1 = SizedQueue.new(2)
  
#push 5
          sq1.push(5)
  
#push 6
              sq1.push(6)
  
#Checks if the SizedQueue is empty or not
                  puts sq1.empty
    ?
  
#Clears the SizedQueue
    sq1.clear()
  
#Checks if the SizedQueue is empty or not
        puts q1.empty
    ?

chevron_right


Output:

false
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for empty ? function in SizedQueue
  
#Create a new SizedQueue q1
sq1 = SizedQueue.new
  
#Checks if the SizedQueue is empty or not
      puts sq1.empty
    ?

chevron_right


Output:

true

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

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.