This package contains RDoc and RDoc::Markup. RDoc is an application that produces documentation for one or more Ruby source files. We work similarly to JavaDoc, parsing the source, and extracting the definition for classes, modules, and methods (along with includes and requires). We associate with these optional documentation contained in the immediately preceding comment block, and then render 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 (the command is ‘rdoc.bat’ under Windows)
% rdoc [options] [names...]
Type "rdoc —help" for an up-to-date option summary.
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.
For information on how to make lists, hyperlinks, etc. with RDoc, see RDoc::Markup.
Comment blocks can be written fairly naturally, either using ’#’ on successive lines of the comment, or by including the comment in an =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, source 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.
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. :nodoc: is global across all files the class or module appears in, so use :stopdoc:/:startdoc: to only omit documentation 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 <drbrain@segment7.net>
Dave Thomas <dave@pragmaticprogrammer.com> is the original author of RDoc.
RDoc is Copyright (c) 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.
| RDocError | = | Error # :nodoc: | ||
| VERSION | = | "2.0.0" | RDoc version you are using | |
| DOT_DOC_FILENAME | = | ".document" | Name of the dotfile that contains the description of files to be processed in the current directory | |
| GENERAL_MODIFIERS | = | %w[nodoc].freeze | ||
| CLASS_MODIFIERS | = | GENERAL_MODIFIERS | ||
| ATTR_MODIFIERS | = | GENERAL_MODIFIERS | ||
| CONSTANT_MODIFIERS | = | GENERAL_MODIFIERS | ||
| METHOD_MODIFIERS | = | GENERAL_MODIFIERS + %w[arg args yield yields notnew not-new not_new doc] | ||
| KNOWN_CLASSES | = | { "rb_cObject" => "Object", "rb_cArray" => "Array", "rb_cBignum" => "Bignum", "rb_cClass" => "Class", "rb_cDir" => "Dir", "rb_cData" => "Data", "rb_cFalseClass" => "FalseClass", "rb_cFile" => "File", "rb_cFixnum" => "Fixnum", "rb_cFloat" => "Float", "rb_cHash" => "Hash", "rb_cInteger" => "Integer", "rb_cIO" => "IO", "rb_cModule" => "Module", "rb_cNilClass" => "NilClass", "rb_cNumeric" => "Numeric", "rb_cProc" => "Proc", "rb_cRange" => "Range", "rb_cRegexp" => "Regexp", "rb_cString" => "String", "rb_cSymbol" => "Symbol", "rb_cThread" => "Thread", "rb_cTime" => "Time", "rb_cTrueClass" => "TrueClass", "rb_cStruct" => "Struct", "rb_cVM" => "VM", "rb_eException" => "Exception", "rb_eStandardError" => "StandardError", "rb_eSystemExit" => "SystemExit", "rb_eInterrupt" => "Interrupt", "rb_eSignal" => "Signal", "rb_eFatal" => "Fatal", "rb_eArgError" => "ArgError", "rb_eEOFError" => "EOFError", "rb_eIndexError" => "IndexError", "rb_eRangeError" => "RangeError", "rb_eIOError" => "IOError", "rb_eRuntimeError" => "RuntimeError", "rb_eSecurityError" => "SecurityError", "rb_eSystemCallError" => "SystemCallError", "rb_eTypeError" => "TypeError", "rb_eZeroDivError" => "ZeroDivError", "rb_eNotImpError" => "NotImpError", "rb_eNoMemError" => "NoMemError", "rb_eFloatDomainError" => "FloatDomainError", "rb_eScriptError" => "ScriptError", "rb_eNameError" => "NameError", "rb_eSyntaxError" => "SyntaxError", "rb_eLoadError" => "LoadError", "rb_mKernel" => "Kernel", "rb_mComparable" => "Comparable", "rb_mEnumerable" => "Enumerable", "rb_mPrecision" => "Precision", "rb_mErrno" => "Errno", "rb_mFileTest" => "FileTest", "rb_mGC" => "GC", "rb_mMath" => "Math", "rb_mProcess" => "Process" | Ruby‘s built-in classes. |
ruby-doc.org is a service of James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, AZ.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.