Configuring RDoc
RDoc has four ways to configure it. Three control how RDoc runs β .rdoc_options, RDoc::Task, and the RDOCOPT environment variable. One controls which files get documented β .document.
Choosing a mechanism
| Mechanism | What it does | When to use |
|---|---|---|
.rdoc_options |
YAML file, persistent | Gems/libraries β committed to the repo |
RDoc::Task (Rakefile) |
Programmatic Ruby API | When the project already uses Rake |
.document |
File selection list | Control which files get documented |
RDOCOPT env var |
Shell override | Not recommended β included for completeness |
Precedence. Command-line flags override .rdoc_options. RDOCOPT is prepended to ARGV, so command-line flags that appear later in the same invocation still win.
Name cheat sheet
Convention: unless flagged in the tables below, a CLI flag converts kebab-case to snake_case for its
.rdoc_optionskey. For example,--hyperlink-allon the command line ishyperlink_all:in YAML.
Watch out for these names and caveats
These options either use a non-obvious name across mechanisms or are not available in every mechanism β the single most common source of confusion.
| Concept | CLI flag | .rdoc_options key |
RDoc::Task attr |
|---|---|---|---|
| Main page | --main / -m |
main_page |
rdoc.main |
| Output directory | --output / -o / --op |
op_dir |
rdoc.rdoc_dir |
| Generator / format | --format / -f / --fmt |
generator_name |
rdoc.generator |
| Template | --template / -T |
(not supported) | rdoc.template |
Include paths (for :include:) |
--include / -i |
rdoc_include |
β (use rdoc.options <<) |
| Copy static files | --copy-files |
static_path |
β |
| All methods | --all / -a |
visibility: :private |
β |
| Skip tests | --no-skipping-tests |
(CLI only) | β |
| Locale | --locale |
locale_name |
β |
| Locale data directory | --locale-data-dir |
locale_dir |
β |
Full naming reference
Every option that is accessible from more than one mechanism. The β column flags rows where the name or availability is surprising.
| β | CLI flag | .rdoc_options key |
RDoc::Task attr |
|---|---|---|---|
| β | --all / -a |
visibility: :private |
β |
--apply-default-exclude |
apply_default_exclude |
β | |
--autolink-excluded-words |
autolink_excluded_words |
β | |
--charset / -c (legacy) |
charset |
β | |
| β | --copy-files |
static_path |
β |
--embed-mixins |
embed_mixins |
β | |
--encoding / -e |
encoding |
β | |
--exclude / -x |
exclude |
β | |
| β | --format / -f / --fmt |
generator_name |
rdoc.generator |
--hyperlink-all / -A |
hyperlink_all |
β | |
| β | --include / -i |
rdoc_include |
β |
--line-numbers / -N |
line_numbers |
β | |
| β | --locale |
locale_name |
β |
| β | --locale-data-dir |
locale_dir |
β |
| β | --main / -m |
main_page |
rdoc.main |
--markup |
markup |
rdoc.markup |
|
| β | --output / -o / --op |
op_dir |
rdoc.rdoc_dir |
--page-dir |
page_dir |
β | |
--show-hash / -H |
show_hash |
β | |
--tab-width / -w |
tab_width |
β | |
| β | --template / -T |
not supported | rdoc.template |
--title / -t |
title |
rdoc.title |
|
--visibility |
visibility: :public etc. |
β | |
--warn-missing-rdoc-ref |
warn_missing_rdoc_ref |
β | |
--webcvs / -W |
webcvs |
β | |
| (no CLI) | canonical_root |
β | |
| (no CLI) | footer_content |
β |
Configuration mechanisms
.rdoc_options
A YAML file at the project root that RDoc auto-loads on every run. The preferred mechanism for gem and library authors β itβs declarative, committed to the repo, and visible to collaborators.
Location. The current working directory. Resolved by RDoc::Options.load_options.
Syntax. A YAML map of option keys to values.
# .rdoc_options title: MyGem main_page: README.md markup: markdown exclude: - test/ - tmp/
Bootstrap it. If you already configure RDoc via CLI flags, run:
rdoc --markup markdown --main README.md --write-options
This writes a .rdoc_options file containing the current settings.
Limitation. Some options cannot be stored in .rdoc_options (they are silently ignored even if you add them). These are flagged in the options reference below. Examples: --dry-run, --force-output, --force-update, --server, --pipe, --no-skipping-tests, --template, --template-stylesheets.
RDoc::Task (Rakefile)
A programmatic alternative that integrates with Rake. Creates these tasks: rdoc, rerdoc, clobber_rdoc, rdoc:coverage, rdoc:server.
Setup.
# Rakefile require 'rdoc/task' RDoc::Task.new do |rdoc| rdoc.main = 'README.md' rdoc.title = 'MyGem' rdoc.rdoc_dir = 'doc' rdoc.markup = 'markdown' rdoc.rdoc_files.include('README.md', 'lib/**/*.rb') rdoc.rdoc_files.exclude('lib/**/*_internal.rb') end
Selecting files to document. rdoc.rdoc_files is a Rake::FileList, so it accepts both include and exclude with shell glob patterns. This is the Rake-native equivalent of passing positional file arguments on the CLI; for regex-pattern exclusion across the full source tree, use the --exclude option (via rdoc.options) instead.
Available attributes. name, rdoc_dir, main, title, template, markup, generator, rdoc_files, options, external.
Escape hatch. RDoc::Task exposes only a handful of attributes as setters. For any other option, append to rdoc.options:
RDoc::Task.new do |rdoc| rdoc.title = 'MyGem' rdoc.options << '--visibility' << 'private' rdoc.options << '--embed-mixins' rdoc.options << '--exclude' << 'test/' end
RDoc::Task also reads .rdoc_options (same loader as the CLI), so you can split: structural settings in .rdoc_options, environment-specific settings in the Rakefile.
.document
A plain-text file that lists which files to document. Unlike the three options mechanisms, it doesnβt set options β it controls what RDoc parses when it recurses into a directory.
How it works. When RDoc enters a directory, if that directory contains a .document file, only the patterns in the file are processed (via Dir.glob relative to the directory). Otherwise RDoc processes every parseable file in the directory.
Syntax.
-
Whitespace-separated patterns (newlines count as whitespace).
-
#starts a comment that runs to the end of the line. -
Patterns are shell globs, evaluated relative to the directory containing the
.documentfile.
Example (this repoβs .document):
*.md *.rdoc lib doc
Per-directory scoping. You can place a .document file inside any subdirectory to narrow what gets documented there:
# lib/internal/.document # Nothing β this subtree is excluded from generated docs.
RDOCOPT environment variable
A shell environment variable whose contents are prepended to ARGV before RDoc parses options.
export RDOCOPT="--show-hash --visibility=private" rdoc
Precedence. Because RDOCOPT is prepended, later command-line flags override it for the same option.
Not recommended for project configuration. RDOCOPT is machine-local and invisible to collaborators β use .rdoc_options instead. It exists for personal overrides (e.g., always turning on --show-hash on your workstation) and for compatibility with the RUBYOPT convention.
Options reference
Each group below renders as a table with these columns:
| Column | Content |
|---|---|
| Option | CLI flag(s) and a brief name |
.rdoc_options |
YAML key, not supported if there is no YAML form, or CLI only if the option exists only on the CLI |
RDoc::Task |
Task attribute, or β if none (use rdoc.options << as an escape hatch) |
| Effective default | Behavior after option setup |
| Notes | Behavior, gotchas, flags |
What to document
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
| Files to document | (none β CLI uses positional args) | rdoc.rdoc_files (a Rake::FileList; supports .include / .exclude) |
current directory recursively when omitted | The set of files RDoc parses. CLI: positional arguments. Rake: a Rake::FileList. .document: per-directory selection. |
--exclude PATTERN / -x |
exclude (array) |
β (or rdoc.rdoc_files.exclude(...) at the file-list level) |
[] + default set |
Regex applied to filenames during processing. Repeatable. Defaults add *~, *.orig, *.rej, *.bak, *.gemspec. |
--[no-]apply-default-exclude |
apply_default_exclude |
β | true |
Turn the default exclude list on/off. |
--no-skipping-tests |
CLI only | β | skip tests | Without this flag, RDoc skips common test directory names (test, spec). |
--page-dir DIR |
page_dir |
β | nil |
Directory holding guides, FAQ, and other non-class pages. Do not reuse filenames from the project root. |
--root DIR |
CLI only | β | current dir | Root of the source tree. Set when building docs outside the source directory. |
--visibility VIS |
visibility: :public etc. |
β | :protected |
Minimum visibility: :public, :protected, :private, or :nodoc (show everything). YAML values must be symbols. |
--all / -a |
visibility: :private |
β | β | Synonym for --visibility=private. |
--include DIR / -i |
rdoc_include (array of paths) |
β | [project root] |
Directories searched to satisfy :include: directives. Comma-separated on the CLI; repeatable. |
--extension NEW=OLD / -E |
CLI only | β | β | Parse files with extension .new as if they had extension .old. Example: -E cgi=rb. |
Appearance & content
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
--title TITLE / -t |
title |
rdoc.title |
nil |
Documentation title. |
--main NAME / -m |
main_page |
rdoc.main |
nil |
File, class, or module shown on the initial page. |
--markup MARKUP |
markup |
rdoc.markup |
'rdoc' |
One of rdoc, markdown, rd, tomdoc. |
--encoding ENCODING / -e |
encoding |
β | UTF-8 |
Output encoding. All input files are transcoded to this encoding. Prefer over --charset. |
--charset CHARSET / -c |
charset |
β | 'UTF-8' |
Legacy. HTML character-set. Use --encoding instead. |
--[no-]line-numbers / -N |
line_numbers |
β | false |
Show line numbers in source code listings. |
--show-hash / -H |
show_hash |
β | false |
Keep the leading # on hyperlinked instance method names. |
--tab-width WIDTH / -w |
tab_width |
β | 8 |
Column width of a tab character. |
--template NAME / -T |
not supported | rdoc.template |
generatorβs template (aliki by default) |
Template to use. YAML template_dir is not a supported persistent setting. |
--template-stylesheets FILES |
CLI only | β | [] |
Extra stylesheets to include with the HTML template. Comma-separated. |
--[no-]embed-mixins |
embed_mixins |
β | false |
Inline mixin methods, attributes, and constants into the including classβs documentation. |
| (no CLI flag) | footer_content |
β | nil |
Aliki theme only. Structured footer links; see Examples. |
--copy-files PATH |
static_path (array) |
β | [] |
File or directory of static assets to copy into the output directory. Repeatable. |
| (no CLI flag; internal) | β | β | true |
output_decoration controls heading decorations. Programmatic only. |
Development & preview
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
--server[=PORT] |
CLI only | (via rdoc:server task) |
false |
Start a live-reloading preview server. Default port 4000. |
--pipe / -p |
CLI only | β | false |
Convert RDoc on stdin to HTML. |
--write-options |
CLI only | β | β | Write a .rdoc_options file from current CLI flags, then exit. |
--[no-]coverage-report[=LEVEL] / --[no-]dcov / -C |
CLI only | (via rdoc:coverage task) |
false |
Print a report on undocumented items; skip file generation. |
--[no-]force-update / -U |
CLI only | β | true |
Scan all sources even if none is newer than the flag file. |
--force-output / -O |
CLI only | β | false |
Write output even if the output directory doesnβt look like an RDoc output directory. |
--[no-]dry-run |
CLI only | β | false |
Donβt write any files. |
-D / --[no-]debug |
CLI only | β | false |
Sets $DEBUG_RDOC; dumps internals. |
--quiet / -q |
CLI only | β | verbosity 1 |
Suppress progress output by setting verbosity to 0. |
--verbose / -V |
CLI only | β | verbosity 1 |
Extra progress output by setting verbosity to 2. |
--[no-]ignore-invalid |
CLI only | β | true |
Ignore unknown options (used when new options meet old .rdoc_options files). |
Cross-references & links
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
--hyperlink-all / -A |
hyperlink_all |
β | false |
Hyperlink every word that matches a method name, even without # or :: prefix. Legacy behavior. |
--autolink-excluded-words WORDS |
autolink_excluded_words (array) |
β | [] |
Words ignored by autolink. Comma-separated on the CLI. |
--webcvs URL / -W |
webcvs |
β | nil |
URL to a web CVS frontend. %s (or appended) is the filename. |
--warn-missing-rdoc-ref |
warn_missing_rdoc_ref |
β | true |
Warn when rdoc-ref: links canβt be resolved. |
| (no CLI flag) | canonical_root |
β | nil |
Preferred root URL for the generated docs; used for <link rel="canonical">. |
| (no CLI flag; internal) | β | β | nil |
class_module_path_prefix β path prefix for class/module pages. Programmatic only. |
| (no CLI flag; internal) | β | β | nil |
file_path_prefix β path prefix for file pages. Programmatic only. |
Output location & format
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
--output DIR / -o / --op |
op_dir |
rdoc.rdoc_dir |
CLI: 'doc'; RDoc::Task: 'html' |
Output directory. RDoc also writes a created.rid marker here. |
--format FORMAT / -f / --fmt |
generator_name |
rdoc.generator |
'aliki' |
Generator name. Installed generators: aliki (HTML, default), darkfish (deprecated, removal in v8.0), ri, pot. |
--ri / -r |
(sets generator_name: ri) |
β | β | Shortcut: generate ri output into ~/.rdoc. |
--ri-site / -R |
(sets generator_name: ri) |
β | β | Shortcut: generate ri output into the site-wide directory. |
Internationalization
| Option | .rdoc_options |
RDoc::Task |
Effective default | Notes |
|---|---|---|---|---|
--locale NAME |
locale_name |
β | nil |
Output locale. |
--locale-data-dir DIR |
locale_dir |
β | 'locale' |
Directory containing locale data (.po files). |
Examples
Minimal gem setup
A .rdoc_options that covers title, entry page, markup, and exclusions:
# .rdoc_options title: MyGem main_page: README.md markup: markdown exclude: - test/ - tmp/
Commit this file to the repo. RubyGemsβ doc generator and rdoc on the command line both pick it up.
Rakefile equivalent
The same outcome via RDoc::Task, using the rdoc.options << escape hatch for options that arenβt exposed as attributes:
# Rakefile require 'rdoc/task' RDoc::Task.new do |rdoc| rdoc.title = 'MyGem' rdoc.main = 'README.md' rdoc.markup = 'markdown' rdoc.options << '--exclude' << 'test/' rdoc.options << '--exclude' << 'tmp/' rdoc.rdoc_files.include('README.md', 'lib/**/*.rb') end
Customizing the Aliki footer
footer_content is a structured YAML value consumed by the Aliki theme. Each top-level key becomes a column; each nested key becomes a link label.
# .rdoc_options
title: MyGem
footer_content:
DOCUMENTATION:
Home: index.html
Guide: guide.html
RESOURCES:
GitHub: https://github.com/me/mygem
Issues: https://github.com/me/mygem/issues
This option is only read by the Aliki generator (the default). Other generators silently ignore it.
Tuning what gets documented
Combining the three knobs that control scope:
.document β narrow what gets parsed at all:
# .document *.md *.rdoc lib
.rdoc_options β exclude specific file patterns and raise the visibility bar:
# .rdoc_options exclude: - lib/mygem/internal/ - '**/*_spec.rb' visibility: :public
Command line β a one-off dry run without skipping test directories:
rdoc --no-skipping-tests --dry-run --verbose