Skip to content

Instantly share code, notes, and snippets.

@namick
Created October 3, 2014 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namick/44dca86721a071c2c988 to your computer and use it in GitHub Desktop.
Save namick/44dca86721a071c2c988 to your computer and use it in GitHub Desktop.
log_method_call
def self.log_method_call(method_name)
original_method = instance_method(method_name)
define_method(method_name) do |*args, &block|
puts caller[3..5]
puts "-> #{self.inspect}##{method_name}(#{args.inspect})"
return_value = original_method.bind(self).call(*args, &block)
puts "<- #{self.inspect}##{method_name} #=> #{return_value.inspect}"
return_value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment