Type:
Class

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

Example

We can use TracePoint to gather information specifically for exceptions:

1
2
3
4
5
6
7
8
9
10
trace = TracePoint.new(:raise) do |tp|
    p [tp.lineno, tp.event, tp.raised_exception]
end
#=> #<TracePoint:0x007f786a452448>
 
trace.enable
#=> #<TracePoint:0x007f786a452448>
 
0 / 0
#=> [5, :raise, #<ZeroDivisionError: divided by 0>]

Events

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

Note do not depend on current event set, as this list is subject to change. Instead, it is recommended you specify the type of events you want to use.

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

:line

execute code 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

:b_call

event hook at block entry

:b_return

event hook at block ending

:thread_begin

event hook at thread beginning

:thread_end

event hook at thread ending

defined_class
  • References/Ruby on Rails/Ruby/Classes/TracePoint

defined_class() Instance Public methods Return class or module of the method

2025-01-10 15:47:30
binding
  • References/Ruby on Rails/Ruby/Classes/TracePoint

binding() Instance Public methods Return the generated binding object from event

2025-01-10 15:47:30
new
  • References/Ruby on Rails/Ruby/Classes/TracePoint

TracePoint.new(*events) { |obj| block } â obj Class Public methods Returns

2025-01-10 15:47:30
inspect
  • References/Ruby on Rails/Ruby/Classes/TracePoint

trace.inspect â string Instance Public methods Return a string containing

2025-01-10 15:47:30
disable
  • References/Ruby on Rails/Ruby/Classes/TracePoint

trace.disable â true or falsetrace.disable { block } â obj Instance Public methods

2025-01-10 15:47:30
trace
  • References/Ruby on Rails/Ruby/Classes/TracePoint

TracePoint.trace(*events) { |obj| block } â obj Class Public methods A

2025-01-10 15:47:30
enabled?
  • References/Ruby on Rails/Ruby/Classes/TracePoint

trace.enabled? â true or false Instance Public methods The current

2025-01-10 15:47:30
enable
  • References/Ruby on Rails/Ruby/Classes/TracePoint

trace.enable â true or falsetrace.enable { block } â obj Instance Public methods

2025-01-10 15:47:30
path
  • References/Ruby on Rails/Ruby/Classes/TracePoint

path() Instance Public methods Path of the file being run

2025-01-10 15:47:30
event
  • References/Ruby on Rails/Ruby/Classes/TracePoint

event() Instance Public methods Type of event See

2025-01-10 15:47:30