While cleaning up my blog I have found an old ruby program from 2005: rtd.rb. What this does it it can create pretty graphs from ruby class hierarchy. Interestingly, it still works :smiley:

It is quite easy to use, here is a small tutorial:

Usage Tutorial

  1. Generate graph for the ruby module time. Create a file rtd-time.rb with this content:
    require "./rtd.rb"
    stats = RubyToDot.new
    stats.hide_current_state
    require 'time'
    puts stats.generate
    

    Now run this command (requires dot, install in Ubuntu with sudo apt install graphviz):

    ruby rtd-time.rb | dot -Tpng >time.png
    

    The generates this graph:

    time

  2. This does not yet look very nice. Let hide the module Kernel, and draw the graph from top down:
    require "./rtd.rb"
    stats = RubyToDot.new
    stats.hide_current_state
    require 'time'
    stats.hide(Kernel)
    stats.left_to_right = false
    puts stats.generate
    

    This is the generated graph:

    time top down

json Example

For larger modules the graph can get pretty complex. E.g. here is a graph for JSON. I’ve hid the modules Kernel and JSON::Ext::Generator::GeneratorMethods::Object. Click to enlarge:

JSON

net/ftp Example

Another graph for net/ftp:

net/ftp

Please post if this is useful to you!