Skip to content

Instantly share code, notes, and snippets.

@manuelmorales
Created May 22, 2012 15:36
Show Gist options
  • Save manuelmorales/2769804 to your computer and use it in GitHub Desktop.
Save manuelmorales/2769804 to your computer and use it in GitHub Desktop.
How to log every single call to a ruby instance
# From http://stackoverflow.com/questions/5513558/executing-code-for-every-method-call-in-a-ruby-module
class ChattyArray < Array
Array.instance_methods.each do |name|
m = instance_method(name)
define_method name do |*args, &block|
# puts caller.grep(/app_name/) if name == :certain_method
puts ([name] + args).inspect
m.bind(self).(*args, &block)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment