Saari Development

This blog is intended to be a log of my (Ali Rizvi's) professional ramblings as a software development engineer. I intend to add logs of my experience with different technologies, software, tech books/articles and related stuff from time to time. My intention is to have an archive for my personal use and public benefit.

Thursday, September 28, 2006

Ruby: ri Command Line Help

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 Class
prompt> 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 refine
your 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 method
ri Hash#delete # shows details of the hash instance's delete method

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

0 Comments:

Post a Comment

<< Home