What is the difference between ri and rdoc
Asked Answered
T

3

37

Whenever I install gems I see ri and rdoc follow. I know this is documentation but what is the difference between the two and how to use them?

Trifacial answered 4/9, 2010 at 20:31 Comment(0)
S
33

RDoc [..] is the embedded documentation generator for the Ruby programming language. [..] RDoc is included as part of the Ruby core distribution.

RDoc also provides the engine for creating Ruby ri data files. ri is (more or less) Ruby's version of man pages, serving up API information from the command line.

From: http://en.wikipedia.org/wiki/RDoc

Stilt answered 4/9, 2010 at 20:42 Comment(1)
So ri is a manual reader that reads only a single format (ri data files), and such a format is one of the formats that RDoc can generate?Suchlike
P
21

To access the local RDoc for your gems, type gem server and point your browser to http://localhost:8808.

If the RDocs for your gems aren't installed, gem rdoc --allwill install the documentation for all of your gems.

It might seem like local documentation isn't necessary. Many developers purposefully skip installing it in favor of online documentation. However, for those of us using legacy tools like Rails 2, it can make finding the right documentation fast and easy.

Partiality answered 28/2, 2013 at 19:5 Comment(1)
I've finally come out of the stone age since this answer and now work on a project using Rails 4. Since I don't need local documentation anymore, I followed the instructions in this question so that documentation won't be installed by default. This makes installing gems and bundle quite a bit faster.Partiality
E
14
  • RDoc automatically generates documentation from the comments and structure of your code. https://github.com/rdoc/rdoc So think Doxygen. Use it to generate automatic documentation for code you have written.
  • ri is offline help files for example if you don't have internet. http://www.caliban.org/ruby/rubyguide.shtml#ri Think perldoc. Use it when you have a question about a class, like ri Enumerator should bring up

Enumerator < Object


= Includes: Enumerable (from ruby core)

(from ruby core) ------------------------------------------------------------------------------ A class which allows both internal and external iteration.

An Enumerator can be created by the following methods. * Kernel#to_enum * Kernel#enum_for * Enumerator.new

Most methods have two forms: a block form where the contents are evaluated for each item in the enumeration, and a non-block form which returns a new Enumerator wrapping the iteration.

enumerator = %w(one two three).each puts enumerator.class # => Enumerator enumerator.each_with_object("foo") do |item,obj| puts "#{obj}: #{item}" end # foo: one # foo: two # foo: three enum_with_obj = enumerator.each_with_object("foo") puts enum_with_obj.class # => Enumerator enum_with_obj.each do |item,obj| puts "#{obj: #{item}" end # foo: one # foo: two # foo: three

This allows you to chain Enumerators together........

Escapement answered 26/2, 2013 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.