Skip to content

Instantly share code, notes, and snippets.

@petitviolet
Created December 17, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petitviolet/cc6e873b24f00c9726ee609d1e7a53c4 to your computer and use it in GitHub Desktop.
Save petitviolet/cc6e873b24f00c9726ee609d1e7a53c4 to your computer and use it in GitHub Desktop.
Tracing method calls using TracePoint
class Debugger
def initialize(events)
@tp = TracePoint.new(*(events || %i[call b_call raise])) do |tp|
tp.binding.irb
end
@tp.disable
end
def trace(&block)
@tp.enable
res = block.call
@tp.disable
res
end
def self.trace(events: nil, &block)
Debugger.new(events).trace(&block)
end
end
def method_a(args)
method_b(args)
end
def method_b(args)
p = -> a { method_c(a) }
p.call(args)
end
def method_c(args)
puts args
end
def main
Debugger.trace do
method_a([1, :x])
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment