Last active
December 22, 2015 23:59
-
-
Save v-yarotsky/6550123 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def nil.+@(*) | |
if Module.last_method_defined | |
method_name, klass = Module.last_method_defined | |
klass.class_eval <<-RUBY | |
alias_method "#{method_name}_without_logging", "#{method_name}" | |
def #{method_name}(*args, &block) | |
p "called #{method_name}" | |
send("#{method_name}_without_logging", &block) | |
end | |
RUBY | |
Module.last_method_defined = nil | |
end | |
end | |
class Module | |
class << self; attr_accessor :last_method_defined; end | |
def method_added(method_name) | |
Module.last_method_defined = [method_name, self] | |
end | |
end | |
class Foo | |
+def foo | |
puts :foo | |
end | |
def bar | |
puts :bar | |
end | |
end | |
Foo.new.foo | |
Foo.new.bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment