Skip to content

Instantly share code, notes, and snippets.

@amicojeko
Created July 13, 2015 13:18
Show Gist options
  • Save amicojeko/c13ed5e6bfb7b9bd9817 to your computer and use it in GitHub Desktop.
Save amicojeko/c13ed5e6bfb7b9bd9817 to your computer and use it in GitHub Desktop.
module HiddenLogger
def inject_log(method_name)
instance_exec(method_name) do |method_name|
def method_name_with_logging
method_name_without_logging
puts "Sarcazzo: #{@foo}"
end
eval("alias :method_name_without_logging :#{method_name}")
eval("alias :#{method_name} :method_name_with_logging")
end
end
end
class Parent
include HiddenLogger
def do_something
@foo = "bar"
puts "do_something from parent"
end
def initialize
inject_log :do_something
end
end
class Child < Parent
def do_something
@foo = "baz"
puts "do_something from child"
end
end
f = Parent.new
c = Child.new
f.do_something
c.do_something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment