Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

ThreadGroup#enclose

thgrp.enclose → thgrp

Prevents threads from being added to or removed from the receiving ThreadGroup.

New threads can still be started in an enclosed ThreadGroup.

Example
ThreadGroup::Default.enclose        #=> #<ThreadGroup:0x4029d914>
thr = Thread.new { Thread.stop }    #=> #<Thread:0x402a7210 sleep>
tg = ThreadGroup.new                #=> #<ThreadGroup:0x402752d4>
tg.add thr
#=> ThreadError: can't move from the enclosed thread group
See also #add #enclosed? #list also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0