Ruby/Language Basics/RDoc

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

documentation for the initialize method.

# The +new+ class method initializes the class.
# === Parameters
# * _debt_ = long-term debt
# * _equity_ = equity
# === Example
#  ratios = Ratios.new( 2, 9 )
 def initialize( debt, equity )
   @debt = debt
   @equity = equity
 end
Text enclosed by plus signs (+new+) will be shown in a typewriter font in XHTML
Text enclosed in underscores (as in _debt_) will be shown in italic. 
Lines preceded by asterisks (*) will be set off as bullets in the XHTML. 
Words preceded by equals signs (such as === Example) will be headings in the result; 
one = for a level-one heading, two == for a level two, and so forth). 
Text that is indented by several spaces will also show up in typewriter font.



List in RDoc

# The <tt>fir</tt> method returns a number.
# === Formula
#     _fir_ debt
#  -------------------- = some result
#  a/e
# === Parameters
# The parameters are:
# * <i>d</i> = debt
# * <i>e</i> = equity
# === Example
#  ratios = Ratios.new( 2, 9)
#  ratios.fir # => some text
#  ratios.fir 1, 5# => some text
 def fir( debt=@debt, equity=@equity )
   ratio = debt/(debt+equity).to_f
   printf( "The long-term debt ratio is %.2f.\n", ratio )
   ratio
 end



Processing Files with RDoc

Assume there is a directory, Ratios, that just contains one file, ratios.rb. 
You could run RDoc without any options or file specifications:
rdoc yourFile.rb



RDoc Basics

The comments before the class definition begins are interpreted as general documentation for the class and are placed before any other documentation. 
Paragraphs in the comments become paragraphs in the documentation. 
Numbered lists (1., 2., 3., etc.) become numbered lists. 
Labels followed by double colons (::) line up the text that follows in tabular form. 
The :title: directive lets RDoc know what you want the title of the XHTML document(s) to be (what goes inside <head><title></title></head>).
 
# This class provides a few methods for calculating financial ratios.
# So far, three methods are available:
# 1. first method (_fir_)
# 2. second method (_sec_)
# 3. third method (_tdr_)
#
# Author:: crossplatform (mailto:in at crossplatform.ru)
#
# :title:Ratios
class Ratios



RDoc options are used like this: rdoc [options] [names...]

If a name on the command line is a directory, it is traversed. 
If no names are specified on the command line, all Ruby files in the current directory (and subdirectories) are processed.
Options include:
 
--accessor , -A accessorname[,..]
    Comma-separated list of additional class methods that should be treated like attr_reader and friends. Option may be repeated. Each accessorname may have =text appended, in which case that text appears where the r/w/rw appears for normal accessors.
--all, -a
    Include all methods (not just public) in the output.
--charset , -c charset
    Specify HTML character-set.
--debug, -D
    Display lots on internal stuff.
--diagram, -d
    Generate diagrams showing modules and classes. You need dot v1.8.6 or later to use the --diagram option correctly. Dot is available from http://www.research.att.ru/sw/tools/graphviz.
--exclude , -x pattern
    Do not process files or directories matching pattern. Files given explicitly on the command line will never be excluded.
--extension , -E new=old
    Treat files ending with .new as if they ended with .old. Using "-E cgi=rb" will cause xxx.cgi to be parsed as a Ruby file.
--fileboxes, -F
    Classes are put in boxes, which represents files, where these classes reside. Classes shared among more than one file are shown with a list of files that are sharing them. Silently discarded if --diagram is not given Experimental.
--fmt , -f chm/html/ri/xml
    Set the output formatter. Available output formatters are chm, html, ri, and xml.
--help, -h
    You"re looking at it.
--help-output, -O
    Explain the various output options.
--image-format , -I gif/png/jpg/jpeg
    Sets output image format for diagrams. Can be png, gif, jpeg, jpg. If this option is omitted, png is used. Requires --diagram.
--include , -i dir[, dir...]
    Set (or add to) the list of directories to be searched when satisfying :include: requests. Can be used more than once.
--inline-source, -S
    Show method source code inline rather than via a pop-up link.
--line-numbers, -N
    Include line numbers in the source code.
--main , -m name
    name will be the initial page displayed.
--merge, -M
    When creating ri output, merge processed classes into previously documented classes of the name name.
--one-file, -1
    Put all the output into a single file.
--op , -o dir
    Set the output directory.
--opname , -n name
    Set the name of the output. Has no effect for HTML.
--promiscuous, -p
    When documenting a file that contains a module or class also defined in other files, show all stuff for that module/class in each files page. By default, only show stuff defined in that particular file.
--quiet, -q
    Don"t show progress as we parse.
--ri, -r
    Generate output for use by ri. The files are stored in the .rdoc directory under your home directory unless overridden by a subsequent --op parameter, so no special privileges are needed.
--ri-site, -R
    Generate output for use by ri. The files are stored in a site-wide directory, making them accessible to others, so special privileges are needed.
--ri-system, -Y
    Generate output for use by ri. The files are stored in a system-level directory, making them accessible to others, so special privileges are needed. This option is intended to be used during Ruby installations.
--show-hash, -H
    A name of the form #name in a comment is a possible hyperlink to an instance method name. When displayed, the # is removed unless this option is specified.
--style , -s stylesheet url
    Specifies the URL of a separate stylesheet.
--tab-width , -w n
    Set the width of tab characters (default is 8).
--template , -T template name
    Set the template used when generating output.
--title , -t text
    Set txt as the title for the output.
--version, -v
    Display RDoc"s version.
--webcvs , -W url
    Specify a URL for linking to a web frontend to CVS. If the URL contains a "%s," the name of the current file will be substituted; if the URL doesn"t contain a "%s," the filename will be appended to it.
For information on where the output goes, use:
rdoc --help-output