Skip to content

Instantly share code, notes, and snippets.

@craigw
Created February 3, 2010 18:05
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 craigw/5226decf57adc11baf46 to your computer and use it in GitHub Desktop.
Save craigw/5226decf57adc11baf46 to your computer and use it in GitHub Desktop.
# Totally untested.
module MethodLogging
def self.included(base)
base.methods.each do |m|
alias_method :"old_#{m}", m
define_method(m) do |args|
puts "Called #{m}(#{args.map{|a|a.inspect}.join(', ')})"
return_value = send("old_#{m}", *args)
puts "# => #{return_value.inspect}"
return_value
end
end
end
end
class Foo
def bar
# ...
end
include MethodLogging
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment