Created
January 19, 2018 01:14
-
-
Save f0ster/7a2ef1fc9289f1190ca5530129963bc5 to your computer and use it in GitHub Desktop.
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 MethodLogger | |
def self.included(base) | |
methods = base.instance_methods(false) + base.private_instance_methods(false) | |
base.class_eval do | |
methods.each do |method_name| | |
original_method = instance_method(method_name) | |
Rails.logger.info "creating override method for #{method_name} #{base}" | |
define_method(method_name) do |*args, &block| | |
Rails.logger.info "-> #{base}##{method_name}(#{args.inspect})" | |
Rails.logger.info "-- #{block}" | |
return_value = original_method.bind(self).call(*args, &block) | |
Rails.logger.info "<- #{base}##{method_name} #=> #{return_value.inspect}" | |
return_value | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment