Last Updated: February 25, 2016
·
758
· romulomachado

Ruby: Grep the Object.methods's array

When your object has too many methods, search something on Object.methods's array is a pain in the ass. I wondered if there's a way to grep it and the answer is yes, there is.

If you are looking for a particular method of an object, you can narrow down the search appending .grep /string/ to Object.methods. For example:

Object.methods.grep /inspect/
=> ["inspect", "pretty_inspect", "pretty_print_inspect"]