Created
July 13, 2015 13:18
-
-
Save amicojeko/c13ed5e6bfb7b9bd9817 to your computer and use it in GitHub Desktop.
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
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