Wednesday, July 14, 2010

Finding an Object's method using grep

I've found that would be pretty handy finding a method on an object :

1 - Use the Rails console
./server/console

2 - How to find a method by name :

Syntax.:
Object.new.methods.grep(/pattern/).sort

Example.:

User.new.methods.grep(/*[Uu]ser*/).sort

You also can compare two objects :

User.new.methods.grep(/*user*/).sort - Object.new.methods