Documenting with RDoc

RDoc does two jobs. Its first job is to analyze source files. Ruby files, of course, but it will also analyze C files and Markdown files. Within those files, RDoc looks for information to document. Its second job is to take this information and convert it into something readable—usually HTML or Ruby’s ri documentation format.

Let’s look at an example.

 class​ Counter
  attr_reader ​:counter
 
 def​ ​initialize​(initial_value = 0)
  @counter = initial_value
 end
 
 def​ ​inc
  @counter += 1
 end
 end

Going into that directory and running rdoc will create an entire doc directory with HTML files.

Here’s what one of the files looks like:

Even though the source contains no internal documentation, ...

Get Programming Ruby 3.3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.