红宝石 |队列关闭?函数
封闭的?是 Ruby 中的一个内置函数,用于检查队列是否关闭?它返回一个布尔值,如果队列已关闭,则返回 true,否则返回 false。
Syntax: q_name.closed?
Parameters: The function does not takes any element.
Return Value: It returns true if the queue is closed else it returns false.
示例 1 :
#Ruby program for closed ? function in Queue
#Create a new QUEUE q1
q1 = Queue.new
#push 5
q1.push(5)
#push 6
q1.push(6)
#Checks if the queue is closed or not
puts q1.empty
?
#Close the queue
q1.close()
#Checks if the queue is closed or not
puts q1.closed
?
输出:
false
true
示例 2 :
#Ruby program for closed ? function in Queue
#Create a new QUEUE q1
q1 = Queue.new
#Checks if the queue is closed ? or not
puts q1.closed
?
输出:
closed
参考:https://devdocs.io/ruby~2.5/queue#method-i-closed-3F