Saari Development

Ruby: ri Command Line Help

Posted in Uncategorized by imsaar on September 28th, 2006

Looking up help on ruby methods and classes from the command line sounds simple but can be very useful if you don’t know or don’t remember.

ri is the equivalent of ‘man’ command in unix (I always confuse this with rdoc which is for generating html documentation, I think perldoc has something to do with this confusion).

Some example commands are

prompt> ri Classprompt> ri alias_method

In case multiple classes have the same method and you are searching for a method

prompt> ri method_missing

ri will show a message like this:

More than one method matched your request. You can refineyour search by asking for information on one of:

   Delegator#method_missing, Kernel#method_missing

You can then look for the specific method using:

prompt> ri Kernel#method_missing

Update: I just discovered that Class#method is for instance methods, if you want to look help class methods then it is done using Class::method.

Example:

ri Hash::new        # shows details of the Hash class's new methodri Hash#delete      # shows details of the hash instance's delete method

Also found this interesting reference:
Ruby RI - Using Ruby’s RI Documentation Reader