class method
TracePoint.new
(*::_ToSym events) { (instance tp) -> void } -> instance
TracePoint.new(*events) { |tp| block } → tp
trace_point.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/trace_point.rb, line 96
def self.new(*events)
Primitive.attr! :use_block
Primitive.tracepoint_new_s(events)
end
Returns a new TracePoint object, not enabled by default.
To activate the TracePoint object, use TracePoint#enable:
Example
trace = TracePoint.new(:call) do |tp| p [tp.lineno, tp.defined_class, tp.method_id, tp.event] end #=> #<TracePoint:disabled> trace.enable #=> false puts "Hello, TracePoint!" # ... # [48, IRB::Notifier::AbstractNotifier, :printf, :call] # ...
To deactivate the trace, use TracePoint#disable.
Example
trace.disable
See Events at TracePoint for possible events and more information.
A block must be given; otherwise, an ArgumentError is raised.
If the trace method isn’t supported for the given event(s) filter, a RuntimeError is raised.
Example
TracePoint.trace(:line) do |tp| p tp.raised_exception end #=> RuntimeError: 'raised_exception' not supported by this event
If the trace method is called outside a block, a RuntimeError is raised.
Example
TracePoint.trace(:line) do |tp| $tp = tp end $tp.lineno #=> access from outside (RuntimeError)
Access from other ractors, threads or fibers is forbidden. TracePoints are active per-ractor so if you enable a TracePoint in one ractor, other ractors will not be affected.