Skip to content

Instantly share code, notes, and snippets.

@akm
Created October 2, 2008 09:19
Show Gist options
  • Save akm/14322 to your computer and use it in GitHub Desktop.
Save akm/14322 to your computer and use it in GitHub Desktop.
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