Published: Nov 21, 2015 by Midwire
Here is my ~/.irbrc
file.
It contains 4 useful methods as follows:
what_methods
Allows you to determine what methods are available on an object without displaying all of Object instance methods. The following irb
session calls what_methods
on an Array instance:
Note: wm
is just a shortcut for what_methods
, cuz I’m lazy.
As you can see, it lists out all public instance methods for the Array instance, ary
.
predicates
Predicates is similar to what_methods
. It actually calls what_methods
and filters out all but methods that end with a question mark (predicates).
Pretty cool, huh?
locate(obj, method)
Have you ever been at some breakpoint and wanted to look at the code for a specific method? This tiny method lets you do just that.
How about that? It even gives you the line number along with the file where the method is defined.
To use these in an irb
session, just copy them into your ~/.irbrc
file. However, that won’t help if you plan to use them during a pry session. For that just copy them into your ~/.pryrc
file.
Enjoy!