Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing ruby standard library documentation locally

Tags:

ruby

ri

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.

like image 200
Mikey Hogarth Avatar asked Nov 22 '11 21:11

Mikey Hogarth


2 Answers

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]
like image 137
Dylan Markow Avatar answered Oct 01 '22 23:10

Dylan Markow


Several options:

  • Local, searchable Rails and Ruby docs (options to add other docs like haml, rspec, rack, etc., but not quite up-to-date)
  • Create from source
  • ri
  • ... and a million tools to generate snazzy docs from Ruby source, including...
  • doc, which generates local searchable docs of whatever you tell it to; I'm digging it
like image 24
Dave Newton Avatar answered Oct 01 '22 23:10

Dave Newton