This package contains RDoc and RDoc::Markup. RDoc is an application that produces documentation for one or more Ruby source files. It works similarly to JavaDoc, parsing the source, and extracting the definition for classes, modules, and methods (along with includes and requires). It associates with these optional documentation contained in the immediately preceding comment block, and then renders the result using a pluggable output formatter. RDoc::Markup is a library that converts plain text into various output formats. The markup library is used to interpret the comment blocks that RDoc uses to document methods, classes, and so on.
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 rdoc.rb
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. 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 and Ruby source files only.
rdoc can be passed a variety of command-line options. In addition, options can be specified via the RDOCOPT environment variable, which functions similarly to the RUBYOPT environment variable.
% export RDOCOPT="-S"
will make rdoc default to inline method source code. Command-line options always will override those in RDOCOPT.
Run:
rdoc --help
for full details on rdoc’s options.
Comment blocks can be written fairly naturally, either using # on successive lines of the comment, or by including the comment in a =begin/=end block. If you use the latter form, the =begin line must be flagged with an RDoc tag:
=begin rdoc Documentation to be processed by RDoc. ... =end
RDoc stops processing comments if it finds a comment line containing a --. This can be used to separate external from internal comments, or to stop a comment being associated with a method, class, or module. Commenting can be turned back on with a line that starts with a ++.
##
# Extract the age and calculate the date-of-birth.
#--
# FIXME: fails if the birthday falls on February 29th
#++
# The DOB is returned as a Time object.
def get_dob(person)
# ...
end
Names of classes, files, and any method names containing an underscore or preceded by a hash character are automatically hyperlinked from comment text to their description.
Method parameter lists are extracted and displayed with the method description. If a method calls yield, then the parameters passed to yield will also be displayed:
def fred
...
yield line, address
This will get documented as:
fred() { |line, address| ... }
You can override this using a comment containing ’:yields: …’ immediately after the method definition
def fred # :yields: index, position
# ...
yield line, address
which will get documented as
fred() { |index, position| ... }
:yields: is an example of a documentation directive. These appear immediately after the start of the document element they are modifying.
RDoc automatically cross-references words with underscores or camel-case. To suppress cross-references, prefix the word with a \ character. To include special characters like “\n”, you’ll need to use two \ characters like “\\n”.
* this is a list with three paragraphs in
the first item. This is the first paragraph.
And this is the second paragraph.
1. This is an indented, numbered list.
2. This is the second item in that list
This is the third conventional paragraph in the
first list item.
* This is the second item in the original list
[cat] a small furry mammal
that seems to sleep a lot
[ant] a little insect that is known
to enjoy picnics
A minor variation on labeled lists uses two colons to separate the label from the list body:
cat:: a small furry mammal
that seems to sleep a lot
ant:: a little insect that is known
to enjoy picnics
This latter style guarantees that the list bodies’ left margins are aligned: think of them as a two column table.
Word-based markup uses flag characters around individual words:
General markup affects text between a start delimiter and and end delimiter. Not surprisingly, these delimiters look like HTML markup.
Unlike conventional Wiki markup, general markup can cross line boundaries. You can turn off the interpretation of markup by preceding the first character with a backslash. This only works for simple markup, not HTML-style markup.
Hyperlinks can also be of the form label[url], in which case the label is used in the displayed text, and url is used as the target. If label contains multiple words, put it in braces: {multi word label}[url].
Example hyperlinks:
link:RDoc.html
http://rdoc.rubyforge.org
mailto:user@example.com
{RDoc Documentation}[http://rdoc.rubyforge.org]
{RDoc Markup}[link:RDoc/Markup.html]
module MyModule # :nodoc:
class Input
end
end
module OtherModule # :nodoc: all
class Output
end
end
In the above code, only class MyModule::Input will be documented. The :nodoc: directive is global across all files for the class or module to which it applies, so use :stopdoc:/:startdoc: to suppress documentation only for a particular set of methods, etc.
Comment blocks can contain other directives:
# ---------------------------------------- # :section: My Section # This is the section that I wrote. # See it glisten in the noon-day sun. # ----------------------------------------
RDoc is currently being maintained by Eric
Hodel
Dave Thomas
RDoc is Copyright © 2001-2003 Dave Thomas, The Pragmatic Programmers. It is free software, and may be redistributed under the terms specified in the README file of the Ruby distribution.
This software is provided “as is” and without any express or implied warranties, including, without limitation, the implied warranties of merchantibility and fitness for a particular purpose.
Ruby’s built-in classes, modules and exceptions
RDoc version you are using
Name of the dotfile that contains the description of files to be processed in the current directory
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.