Created
February 3, 2013 17:35
-
-
Save langalex/4702735 to your computer and use it in GitHub Desktop.
Extend an object with this module to print out all method calls to it.
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 LogCalls | |
def self.extended(b) | |
b.class_eval do | |
(b.methods - Object.methods).each do |m| | |
define_method "#{m.to_s.gsub(/[\?\!=]/, '')}_with_logging#{m.to_s[/[\?\!=]/]}" do |*args| | |
puts m | |
send "#{m.to_s.gsub(/[\?\!=]/, '')}_without_logging#{m.to_s[/[\?\!=]/]}", *args | |
end | |
alias_method_chain m.to_sym, :logging | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment