10

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Mikey Hogarth
  • 4,672
  • 7
  • 28
  • 44
  • 1
    Are you coding offline a lot? Cause if not, the docs are always there at http://rubydoc.info/stdlib. – Michael Kohl Nov 22 '11 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 – Mikey Hogarth Nov 22 '11 at 23:01

3 Answers3

13

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]
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • 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 – Mikey Hogarth Nov 22 '11 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! – Mikey Hogarth Nov 22 '11 at 23:02
  • Nope, `drop` was around in 1.8.x. But glad to hear it's working otherwise. – Dylan Markow Nov 22 '11 at 23:34
  • @MikeyHogarth What do you get when you type `ri drop`? What classes are shown? – Dave Newton Nov 23 '11 at 00:01
  • 1
    Also, if you're using RVM, you may need to run `rvm docs generate` to avoid the "Nothing known about..." errors. – Dylan Markow Nov 23 '11 at 02:44
  • 1
    I am not using `rvm` so how should I get to see the documentation locally? – Arup Rakshit Sep 14 '13 at 21:01
  • What is the option for non-rvm users? – Anwar Jun 06 '15 at 17:31
  • @Anwar How did you install ruby? I use rbenv now, and `ri` just works without having to do anything. – Dylan Markow Jun 06 '15 at 20:16
  • I used ubuntu's package installer to install ruby 1.9.1 and rvm to install 2.2.0 – Anwar Jun 07 '15 at 03:11
5

Several options:

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 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 '13 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. – Dave Newton Sep 14 '13 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 git@github.com: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

Em-AK
  • 3,104
  • 2
  • 12
  • 11