Friday, September 14, 2007

Cheap Tricks IX - Spying on Ruby

St. Louis was fun. They have a very active Java user community and met loads of nice folks. Other than that, not much new or exciting today. Crashed on a friend's couch last night so brain not function so good.

But... here is some fun Ruby-spying techniques to help round out the week. The first one attaches a trace to "require" and prints out the file and line that is making the first call to "require":

Here is a way to trace every line that creates a new object.

A little more generalized, here we trace calls to specific methods for a given class that "requests" to be traced:

And here is how any class can request it's methods be traced:

Finally, you can add a little extra zing by cleaning up the output of the "caller.shift" file location like so:

0 comments: