Created
October 2, 2008 09:19
-
-
Save akm/14322 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
class Module | |
def def_trace_method(method_name, suffix = :rubeus) | |
self.module_eval(<<-"EOS") | |
def #{method_name.to_s}_with_#{suffix.to_s}(*args, &block) | |
puts "\#{self.name}.#{method_name}(\#{args.map{|arg| arg.inspect}.join(', ')})" | |
puts caller.join("\n ") if block_given? | |
#{method_name.to_s}_without_#{suffix.to_s}(*args, &block) | |
end | |
EOS | |
self.module_eval do | |
alias_method "#{method_name.to_s}_without_#{suffix.to_s}".to_sym, method_name.to_sym | |
alias_method method_name.to_sym, "#{method_name.to_s}_with_#{suffix.to_s}".to_sym | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment