Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Thread::Queue.new

[E = untyped] () -> ::Thread::Queue[E]
Thread::Queue.new → empty_queue
Thread::Queue.new(enumerable) → queue

Document-method: Queue::new

Creates a new queue instance, optionally using the contents of an enumerable for its initial state.

Example:

Example
q = Thread::Queue.new
#=> #<Thread::Queue:0x00007ff7501110d0>
q.empty?
#=> true

q = Thread::Queue.new([1, 2, 3])
#=> #<Thread::Queue:0x00007ff7500ec500>
q.empty?
#=> false
q.pop
#=> 1

Ruby version changes

  1. 3.1
See also #<< #clear also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1