Open In App

Ruby | SizedQueue empty? function

Improve
Improve
Like Article
Like
Save
Share
Report

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:




#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
    ?


Output:

false
true

Example 2:




#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
    ?


Output:

true

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



Last Updated : 09 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads