Skip to content

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

instance method

TracePoint#disable

trace.disable → true or false
trace.disable { block } → obj

Deactivates the trace

Return true if trace was enabled. Return false if trace was disabled.

Example
trace.enabled?      #=> true
trace.disable       #=> true (previous status)
trace.enabled?      #=> false
trace.disable       #=> false

If a block is given, the trace will only be disable within the scope of the block.

Example
trace.enabled?
#=> true

trace.disable do
    trace.enabled?
    # only disabled for this block
end

trace.enabled?
#=> true

Note: You cannot access event hooks within the block.

Example
trace.disable { p tp.lineno }
#=> RuntimeError: access from outside
See also #defined_class #enable #callee_id #enabled? also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1