Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created January 26, 2013 09:20
Show Gist options
  • Save flash-gordon/4641262 to your computer and use it in GitHub Desktop.
Save flash-gordon/4641262 to your computer and use it in GitHub Desktop.
Little object extension that provide method calling tracking
class Object
# class MyObject
# end
#
# obj = MyObject.new
# obj.ring_it! # Start tracking
# # Logs will appear in rails log (tweak as you wish)
# # Do not use in production! Only for debug
def ring_it!
return if @__ringed__
raise ArgumentError, 'Only objects with eigenclass allowed' if Symbol === self || Fixnum === self
class_name = self.class.name
object_id = self.object_id
(methods - [:ring_it!, :caller, :instance_eval, :method]).each do |method_name|
method = method(method_name)
src_location = method.source_location || [nil, nil]
instance_eval(<<-EVAL, *src_location.compact)
def #{method_name}(*args)
Rails.logger.info(caller.first + " - Object ringing. Object #{class_name}##{object_id}. Method: :#{method_name}. Arguments: " + args.inspect)
super
end
EVAL
end
@__ringed__ = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment