TracePoint.new(*events) { |obj| block } รข obj
Class Public methods
Returns a new TracePoint object, not enabled by default.
Next, in order to activate the trace, you must use #enable
trace = TracePoint.new(:call) do |tp| p [tp.lineno, tp.defined_class, tp.method_id, tp.event] end #=> #<TracePoint:0x007f17372cdb20> trace.enable #=> #<TracePoint:0x007f17372cdb20> puts "Hello, TracePoint!" # ... # [48, IRB::Notifier::AbstractNotifier, :printf, :call] # ...
When you want to deactivate the trace, you must use #disable
trace.disable
See Events at TracePoint for possible events and more information.
A block must be given, otherwise a ThreadError 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.line #=> access from outside (RuntimeError)
Access from other threads is also forbidden.
Please login to continue.