Wednesday, August 29, 2007

Handy IRB Trick: grep_classes Method

Just before New Year's 2006, James Gray and Pat Maddox both showed me how to create a Scriptaculous autocomplete dropdown with real-time contents from Ruby's ObjectSpace, which you could use to create a Rails app which performed reflection via Ajax.

The other day, I realized the code is a lot more useful if you put it in your .irbrc file. Here's the version I use in mine (behind the link). I repurposed it into a method called grep_classes. It does exactly what it says on the tin - greps existing classes for whatever string you pass it. Very handy when you're interacting with a controller in IRB and can't remember the exact name of the mock request class used in functional tests (for example).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.