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
1 2 3 4 5 6 7 8 9 10 11 12 | 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
1 | 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.
1 2 3 4 | 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.
1 2 3 4 | 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.