Unfortunately I couldn't find a clean, automated solution that would magically wrap all instance and class methods in a Class so I could see when they were called.
So I wrote one in pure ruby, using the fantastic ability to 'prepend' a module, and initially inspired by "How I Built Timeasure" (see links below)
The solution is robust and is even stackable, if you would want to do such a thing, and it should not generally be "breakable" by the class module as long as it doesn't 'unprepend' the wrapper.
It has some example test code at the end ('class Foo') so you can just run the script to see it work, obviously you'd want to delete that to include this in your project.
class Foo @@wrapper = Wrapper.wrap(self) ....define the rest of Class Foo here.... endIf you don't need to ask the wrapper object from the wrapped class, then you can make this a little cleaner/simpler:
class Foo Wrapper.wrap(self) ....define the rest of Class Foo here.... endYou could also do this so you can just put "watch_this_class" at the top of every class you want to watch
class Class def watch_this_class @@wrapper = Wrapper.wrap(self) end endOr you could inherit this object if you want to use inheritance
class WatchedObj def self.inherited(subclass) @@wrapper = Wrapper.wrap(subclass) end endIf you don't have the ability to edit the class you want to wrap, you can also define this before-hand (or else do the ipso-facto wrapping mentioned at the top of Wrapper)
class Foo @@wrapper = Wrapper.wrap(self) end
If you find any, please feel free to contact me
Back to Solutions.