11

I'm just getting into Ruby - one of the things I'm having a little trouble letting go of is Intellisense / code completion, so if I don't have that I really need to have the API close to hand at all times. I made the discovery last week of:

gem server

which starts a server which lets you check out the documentation for all of your installed gems. Is there an equivalent to this which allows you to browse the standard libraries instead of the gems?

Using Linux/Ruby 1.8.7.

2
  • 1
    Are you coding offline a lot? Cause if not, the docs are always there at rubydoc.info/stdlib. Nov 22, 2011 at 21:45
  • 3
    Yeah i code offline a lot while commuting, been using rubydoc when i'm at home but it would still be good to get the docs at the command line Nov 22, 2011 at 23:01

3 Answers 3

14

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]
9
  • I think I'm still missing something dude - this is what I get from your cmd (although I have noticed ri works for other things though): mikey@mikey-netbook:~$ ri Array#drop Invalid gemspec in [/var/lib/gems/1.8/specifications/json_pure-1.6.1.gemspec]: invalid date format in specification: "2011-09-18 00:00:00.000000000Z" Nothing known about Array#drop Nov 22, 2011 at 22:35
  • it's cool, i think drop might be a 1.9.2 method, the ri command does work for other methods. CHeers! Nov 22, 2011 at 23:02
  • Nope, drop was around in 1.8.x. But glad to hear it's working otherwise. Nov 22, 2011 at 23:34
  • 1
    Also, if you're using RVM, you may need to run rvm docs generate to avoid the "Nothing known about..." errors. Nov 23, 2011 at 2:44
  • 1
    I am not using rvm so how should I get to see the documentation locally? Sep 14, 2013 at 21:01
5

Several options:

2
  • 1
    The first (railsapi.com) is out of date, ri is pretty basic (when you're used to documentation via an IDE or via a web browser - firstly you have to know the class you want the docs on and secondly it doesn't alway work - e.g. ri String gives Nothing known about String) and the last (doc) didn't work for me with Ruby 2.0.0.
    – Snowcrash
    Sep 14, 2013 at 20:42
  • @SnowCrash 1 that's what I said, 2 it is what it is-it's the docs that are in the code, and if you don't generate the docs, there's nothing to show, and 3 could be, but two years ago Ruby 2 didn't really matter. Sep 14, 2013 at 23:22
3

Devdocs does the job

  • it works (also) offline
  • it is not limited to the ruby doc ;)

Clone the repo from github:

git clone [email protected]:Thibaut/devdocs.git
cd devdocs

Install dependencies:

gem install bundler
bundle install

download the docs:

thor docs:download --all

Run it:

rackup

It's accessible by default at http://localhost:9292

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.