Skip to content

Instantly share code, notes, and snippets.

@rsanheim
Created June 26, 2009 04:28
Show Gist options
  • Select an option

  • Save rsanheim/136301 to your computer and use it in GitHub Desktop.

Select an option

Save rsanheim/136301 to your computer and use it in GitHub Desktop.
def self.log(method, options = {})
the_logger = options[:logger] || send(:logger)
meth = the_logger.respond_to?(:debug) ? :debug : :puts
define_method("#{method}_with_logging") do |*args|
the_logger.send(meth, "Before method: #{method} arguments: #{args.inspect}")
result = send("#{method}_without_logging", *args)
the_logger.send(meth, "After method: #{method} result: #{result.inspect}")
result
end
alias_method_chain method, "logging"
end
log :build_groups_for_select, :logger => logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment