What is the fastest way to get to documentation for Ruby? [closed]
-
02-07-2019 - |
Question
Say I'm writing some ruby code and I want to use the standard Date type to get the current date. Instead of using a search engine, is there a faster way to find the documentation for this class? I know I can get the methods for Date by typing Date.methods
, but as far as I know this doesn't provide details about argument types or return value.
Editor-specific answers are welcomed. My editor of choice is Emacs.
Solution
Bookmark the ruby core docs
Use your web browser's find-text command.
Unexpected as it may seem, I find this is actually quicker than using ri
, which for some reason seems to take ages to start up.
It is also much better than ri
because the HTML page lists all the documentation for all the methods on a single page. Often methods are related to others, and switching between 2 ri
's is painful
OTHER TIPS
On your console use "ri"
ri Date
That works with all classes. (e.g. ri String) To see documentation for a particular method you use this:
ri Date#yourMethod
The canonical source for Ruby documentation is Ruby-doc - the two links there which are of the most interest are core and standard library. You get a javadoc-style representation which usually covers argument types and return values. You can even make your own with RDoc.
For those of you who want docs from within vanilla IRB
Follow these instructions for setting up the core RI documentation. As of writing, the steps are
$ cd ~/.rvm/src $ rvm docs generate-ri
Now you can view docs for a specific method on the command line using the
ri
command. To invoke it from within IRB, use the help command:$ irb irb(main):001:0> help 'String#chomp'