Last Updated: February 25, 2016
·
977
· citizen428

Ruby 2.0: TracePoint

Ruby 2.0 deprecates Kernel#set_trace_func in favor of the TracePoint class which has a nice object-oriented API. For example, tracing all C-calls can be as easy as

trace = TracePoint.trace(:c_call) { |tp| [tp.lineno, tp.event] }

which is a convenient shortcut for

trace = TracePoint.new(:c_call) do |tp|
  p [tp.lineno, tp.event]
end

trace.enable