Skip to content

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

class method

TracePoint.trace

(*::_ToSym events) { (instance tp) -> void } -> instance
TracePoint.trace(*events) { |tp| block } → obj

A convenience method for TracePoint.new that activates the trace automatically.

Example
trace = TracePoint.trace(:call) { |tp| [tp.lineno, tp.event] }
#=> #<TracePoint:enabled>

trace.enabled?  #=> true
See also .stat #binding .new #callee_id also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0