Skip to content

Instantly share code, notes, and snippets.

@lewispb
Created December 22, 2023 00:21
Show Gist options
  • Save lewispb/b8afd7f0912defb0ba2cafda3c738469 to your computer and use it in GitHub Desktop.
Save lewispb/b8afd7f0912defb0ba2cafda3c738469 to your computer and use it in GitHub Desktop.
tracepoint
class TestObj
def method_missing(method_name, *args)
if method_name == :works?
true
else
super
end
end
def respond_to_missing?(method_name, include_private = false)
method_name == :works? || super
end
def something_else?
false
end
end
TracePoint.new(:a_call) { |tp| puts tp.inspect }.enable do
TestObj.new.works?
end
# Output:
#<TracePoint:b_call test.rb:19>
#<TracePoint:c_call `new' test.rb:20>
#<TracePoint:c_call `initialize' test.rb:20>
#<TracePoint:call `method_missing' test.rb:2>
#<TracePoint:c_call `==' test.rb:3>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment