Skip to content
rubyPublic

About

RDoc produces HTML and online documentation for Ruby projects.

Topics

Resources

Contributing

Security policy

Stars

931 stars

Watchers

57 watching

Forks

Latest commit

 

History

4,209 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RDoc - Ruby Documentation System

RDoc

Description

RDoc produces HTML and command-line documentation for Ruby projects. RDoc includes the rdoc and ri tools for generating and displaying documentation from the command-line.

Generating Documentation

Once installed, you can create documentation using the rdoc command

rdoc [options] [names...]

For an up-to-date option summary, type

rdoc --help

A typical use might be to generate documentation for a package of Ruby source (such as RDoc itself).

rdoc

This command generates documentation for all the Ruby and C source files in and below the current directory. These will be stored in a documentation tree starting in the subdirectory doc.

You can make this slightly more useful for your readers by having the index page contain the documentation for the primary file. In our case, we could type

rdoc --main README.md

You'll find information on the various formatting tricks you can use in comment blocks in the documentation this generates.

RDoc uses file extensions to determine how to process each file. File names ending .rb and .rbw are assumed to be Ruby source. Files ending .c are parsed as C files. Files ending .rbs are parsed as RBS signature files. All other files are assumed to contain just Markup-style markup (with or without leading # comment markers). If directory names are passed to RDoc, they are scanned recursively for C, Ruby, and RBS source files.

RBS files can document classes, modules, methods, attributes, and constants. When RBS declarations match objects already documented from Ruby source, their comments and type signatures extend the existing documentation.

To generate documentation using rake see RDoc::Task.

To generate documentation programmatically:

require 'rdoc/rdoc'

options = RDoc::Options.new
options.files = ['a.rb', 'b.rb']
options.setup_generator 'aliki'
# see RDoc::Options

rdoc = RDoc::RDoc.new
rdoc.document options
# see RDoc::RDoc

You can specify the target files for document generation with .document file in the project root directory. .document file contains a list of file and directory names including comment lines starting with #. See https://github.com/ruby/rdoc/blob/master/.document as an example.

Writing Documentation

To write documentation for RDoc, place a comment above the class, module, method, constant, or attribute you want documented:

##
# This class represents an arbitrary shape by a series of points.
class Shape
  ##
  # Creates a new shape described by a +polyline+.
  #
  # If the +polyline+ does not end at the same point it started at the
  # first pointed is copied and placed at the end of the line.
  #
  # An ArgumentError is raised if the line crosses itself, but shapes may
  # be concave.
  def initialize polyline
    # ...
  end
end

Markup Formats

RDoc supports multiple markup formats:

Format File Extensions Default For
RDoc .rdoc .rb, .c files
Markdown .md None
RD .rd None
TomDoc N/A None

RDoc markup is currently the default format for Ruby and C files. However, we plan to retire it in favor of Markdown in the future.

Markdown support is actively being improved. Once it reaches feature parity with RDoc markup, it will become the default format.

For standalone documentation files, we recommend writing .md files instead of .rdoc files.

RD and TomDoc are legacy formats. We highly discourage their use in new projects.

Specifying Markup Format

Per-file: Add a :markup: directive at the top of a Ruby file:

# :markup: markdown

# This class uses **Markdown** for documentation.
class MyClass
end

Per-project: Create a .rdoc_options file in your project root:

markup: markdown

Command line:

rdoc --markup markdown

Feature Differences

Feature RDoc Markup Markdown
Headings = Heading # Heading
Bold *word* **word**
Italic _word_ *word*
Monospace