How to get the Ruby documentation from the command line
If you're using RVM
to manage your Ruby installations you can do this:
rvm docs generate
If not, try doing this:
gem install rdoc-data
rdoc-data --install
then try the ri
command again.
open ruby gem documentation from the command line
Ref. http://guides.rubygems.org/rubygems-basics/#viewing-documentation
You can use ri [options] [names]
command, e.g. ri RBTree
. ri --help
for more info.
or gem server
command, where you can access the docs at localhost:8808
How to get documentation for a method in a Ruby gem?
As an alternative to using external sites, you can try ri
from the command line:
ri "can?"
When you install a gem, the ri documentation is (usually) installed as well. The ri
command line tool will search installed gem documentation for methods and constants matching your input and present them.
Since it runs locally, this can be a great resource when you don't have an internet connection handy!
accessing ruby standard library documentation locally
In your terminal, you can use ri
to print specific parts of the documentation. (Note that if you're using RVM to manage your ruby installation(s), you may need to run rvm docs generate
to avoid getting "Nothing known about...." responses)
For example:
> ri Array#drop
would output:
------------------------------------------------------------- Array#drop
ary.drop(n) => array
------------------------------------------------------------------------
Drops first n elements from _ary_, and returns rest elements in an
array.
a = [1, 2, 3, 4, 5, 0]
a.drop(3) # => [4, 5, 0]
Where to find the ruby executable documentation?
Easiest option is to run man ruby
. It will show your locally installed interpreter options.
Definitive option is the ruby repository on GitHub. Navigate to the version you need in the releases and locate man/ruby.1
file in the tree. The file contains definitions for CLI arguments.
Example: Ruby 2.3.0 interpreter CLI arguments definitions are here.
Reading docs in irb
Pry is a Ruby version of IPython, it supports the ?
command to look up documentation on methods, but uses a slightly different syntax:
pry(main)> ? File.dirname
From: file.c in Ruby Core (C Method):
Number of lines: 6
visibility: public
signature: dirname()
Returns all components of the filename given in file_name
except the last one. The filename must be formed using forward
slashes (/'') regardless of the separator used on the
local file system.
File.dirname("/home/gumby/work/ruby.rb") #=> "/home/gumby/work"
You can also look up sourcecode with the $
command:
pry(main)> $ File.link
From: file.c in Ruby Core (C Method):
Number of lines: 14
static VALUE
rb_file_s_link(VALUE klass, VALUE from, VALUE to)
{
rb_secure(2);
FilePathValue(from);
FilePathValue(to);
from = rb_str_encode_ospath(from);
to = rb_str_encode_ospath(to);
if (link(StringValueCStr(from), StringValueCStr(to)) < 0) {
sys_fail2(from, to);
}
return INT2FIX(0);
}
See http://pry.github.com for more information :)
How to document Ruby code?
You should target your documentation for the RDoc processor, which can find your documentation and generate HTML from it. You've put your comment in the right place for that, but you should have a look at the RDoc documentation to learn about the kinds of tags that RDoc knows how to format. To that end, I'd reformat your comment as follows:
# Runs a subprocess and applies handlers for stdout and stderr
# Params:
# +command+:: command line string to be executed by the system
# +outhandler+:: +Proc+ object that takes a pipe object as first and only param (may be nil)
# +errhandler+:: +Proc+ object that takes a pipe object as first and only param (may be nil)
What is the fastest way to get to documentation for Ruby?
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
Related Topics
Rails Plugin for API Key + Secret Key Signing
How to Pass Arguments from the Parent Task to the Child Task in Rake
Configuring Jekyll for Github Project Pages
Ruby: What Does the Snippet: (Num & 1) == 0 Exactly Do
How to Switch to Older Versions of the Ruby/Rails Environment
How to Controller (Start/Kill) a Background Process (Server App) in Ruby
How to Do Basic Authentication Over Https in Ruby
Cucumber, Capybara and Selenium - Submitting a Form Without a Button
Errno::Enoent: No Such File or Directory Ruby
Carrierwave: Create the Same, Unique Filename for All Versioned Files
How to Get the Ruby Documentation from the Command Line
How to Test a Ruby Application Which Uses Mechanize
Rails Scope Find with Current User
What Are the Uppercase and Lowercase Rules of Ruby Method Name
Rails: Creating a Custom Data Type/Creating a Shorthand
How to Check If a Number Is Included in a Range (In One Statement)