Skip to content

Instantly share code, notes, and snippets.

@krists
Created October 10, 2023 14:05
Show Gist options
  • Save krists/fe146b6c5d4c2bfb8e3f24fae5ca6bf5 to your computer and use it in GitHub Desktop.
Save krists/fe146b6c5d4c2bfb8e3f24fae5ca6bf5 to your computer and use it in GitHub Desktop.
MyTracer
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