Created
October 10, 2023 14:05
-
-
Save krists/fe146b6c5d4c2bfb8e3f24fae5ca6bf5 to your computer and use it in GitHub Desktop.
MyTracer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTracer < BasicObject | |
def initialize(obj) | |
@original_obj = obj | |
end | |
def method_missing(method, *args, **kw_args, &block) | |
if @original_obj.respond_to?(method) | |
::Kernel.puts "Method Missing: #{method} | #{args.inspect} | #{kw_args.inspect}" | |
@original_obj.send(method, *args, **kw_args, &block) | |
else | |
super | |
end | |
end | |
def respond_to_missing?(method, include_private = false) | |
(@original_obj.respond_to?(method, include_private) || super).tap do |value| | |
::Kernel.puts "Asked if responds to method #{method} and responded with: #{value}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment