method

new

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: TracePoint
new(*args) public

Returns a new TracePoint object, not enabled by default.

Next, in order to activate the trace, you must use TracePoint#enable

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]
# ...

When you want to deactivate the trace, you must use TracePoint#disable

trace.disable

See TracePoint@Events for possible events and more information.

A block must be given, otherwise an ArgumentError is raised.

If the trace method isn’t included in the given events filter, a RuntimeError is raised.

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 block, a RuntimeError is raised.

TracePoint.trace(:line) do |tp|
  $tp = tp
end
$tp.lineno #=> access from outside (RuntimeError)

Access from other threads is also forbidden.

Show source
Register or log in to add new notes.