Register now and start sharing your code snippets.
-->

How to parse RI generated documentation using RDoc and Ruby

Ruby posted about 1 year ago by christian

RI stores the generated documentation as YAML files. This code uses RDoc to parse the YAML files:

   1  require 'yaml'
   2  require 'find'
   3  require "rdoc/ri/ri_driver"
   4  
   5  dirs = RI::Paths::PATH
   6  dirs.each do |dir|
   7    Find.find(dir) do |fn|
   8      next unless File.file?(fn)
   9      doc = YAML.load(File.read(fn))
  10      next unless doc.respond_to?(:comment)
  11      next unless doc.comment
  12      
  13      # Print name of object
  14      puts doc.full_name
  15      
  16      # Print the body: RDoc comments, but only partial...
  17      puts doc.comment.map{|f| f.body if f.respond_to?(:body)}.join("\n")
  18    end
  19  end

Originally from the article Fun with Ferret.

Tagged rdoc, ri, documentation, ruby