Ruby - Module RDoc


RDoc stands for "Document Generator for Ruby Source."

It's a tool that reads through your Ruby source code files and creates structured HTML documentation.

It comes with the standard Ruby distribution.

RDoc understands Ruby syntax and can create documentation for classes, methods, modules.

The RDoc way to document your code is to leave comments prior to the definition of the class, method, or module you want to document.

For example:

# This class stores information about people. 
 class Person 
  attr_accessor :name, :age, :gender 

  # Create the person object and store their name 
  def initialize(name) 
    @name = name 

  # Print this person's name to the screen 
  def print_name 
    puts "Person called #{@name}" 

This is a simple class that's been documented using comments.

RDoc can turn it into a pretty set of HTML documentation.

To use RDoc, run it from the command line using rdoc <name of source file>.rb, like so:

rdoc person.rb 

This command tells RDoc to process person.rb and produce the HTML documentation.

Once RDoc has completed, you can open index.html, located within doc, and you should see some basic documentation.

Related Topics