class TracePoint

A class that provides the functionality of Kernel#set_trace_func in a well-structured Object-Oriented API.

Example

Use TracePoint to gather information specifically for exceptions:

trace = TracePoint.new(:raise) do |tp|
  p [tp.lineno, tp.event, tp.raised_exception]
end
#=> #<TracePoint:disabled>

trace.enable  #=> false

0 / 0
#=> [5, :raise, #<ZeroDivisionError: divided by 0>]

Events

If you don’t specify the types of events you want to listen for, TracePoint will include all available events.

<strong>Note:</strong> Do not depend on the current event set, as this list is subject to change. Instead, it is recommended to specify the types of events you want to use.

To filter what is traced, you can pass any number of the following as events:

:line : Execute an expression or statement on a new line.

:class : Start a class or module definition.

:end : Finish a class or module definition.

:call : Call a Ruby method.

:return : Return from a Ruby method.

:c_call : Call a C-language routine.

:c_return : Return from a C-language routine.

:raise : Raise an exception.

:rescue : Rescue an exception.

:b_call : Event hook at block entry.

:b_return : Event hook at block ending.

:a_call : Event hook at all calls (call, b_call, and c_call).

:a_return : Event hook at all returns (return, b_return, and c_return).

:thread_begin : Event hook at thread beginning.

:thread_end : Event hook at thread ending.

:fiber_switch : Event hook at fiber switch.

:script_compiled : New Ruby code compiled (with eval, load, or require).