Skip to content

Instantly share code, notes, and snippets.

@v-yarotsky
Last active December 22, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v-yarotsky/6550123 to your computer and use it in GitHub Desktop.
Save v-yarotsky/6550123 to your computer and use it in GitHub Desktop.
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