Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Thread.new

Thread.new { ... } → thread
Thread.new(*args, &proc) → thread
Thread.new(*args) { |args| ... } → thread
Creates a new thread executing the given block.
Any +args+ given to ::new will be passed to the block:
arr = []
a, b, c = 1, 2, 3
Thread.new(a,b,c) { |d,e,f| arr << d << e << f }.join
arr #=> [1, 2, 3]
A ThreadError exception is raised if ::new is called without a block.
If you're going to subclass Thread, be sure to call super in your
+initialize+ method, otherwise a ThreadError will be raised.
No documentation available
See also .main .pass .list .pending_interrupt? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0