title: "ri" description: > Ruby documentation through the ri CLI, and console. categories: posts
TL;DR
Ruby comes with a built-in namespace index which can be access through the ri
CLI, and console.
Table of Contents
To list all namespaces ri
knows about simply
$ ri -l
We can also list all classes, and modules within a given namespace.
$ ri Psych -l
$ ri Hash # for full namespace
$ ri 'String::new' # for class methods
$ ri 'Array#<<' # for instance methods
$ ri 'Array.[]' # for class and instance methods
Note the use of quotes when querying for method documentation.
Expand the ri
documentation library with
$ gem install minitest --document ri
$ gem update minitest --document ri
Alternatively, add to the local development .gemrc
file
install: --document ri
update: --document ri
Unused documentation gets removed automatically with:
$ gem cleanup
By default, ri
includes Ruby core and standard libraries, as well as site_lib
,
RubyGems documentation, and ~/.rdoc
. Other directories may be added via:
$ ri SomeNamespace -d=path/to/local/doc/dir
We can rebuild the index for any gem with
$ gem rdoc <gem_name> --ri --no-rdoc --overwrite
or for all at once with
$ gem rdoc --all --ri --no-rdoc --overwrite
To start a console session simply run ri
at the terminal without any arguments.
To end the ri
session simply hit ENTER
on an empty console prompt.
$ ri -h
$ man ri