On Thu, 15 Apr 2004 14:48:18 +0900, Mehr, Assaph (Assaph) wrote:
> A simple script that generates a graph of the ruby class hierarchy.
> The script relies on GraphViz[1] for generation of the PNG and HTML map
> files.
> Take a look at the basic Ruby class hierarchy on the project web site:
> http://objectgraph.rubyforge.org/.

I have done something similar which builds a tree of the exception 
hierarchy for my book. Output is DocBook format.

See attached for code for details.

output can bee seen on
http://neoneye.dk/rubybook/exceptions.html

--
Simon Strandgaard

server> expand -t2 ruby_exceptions.rb 
parents = []
ObjectSpace.each_object do |obj|
  if obj.class == Class and obj.superclass == Exception
    #puts "class-derived-from-exc #{obj}"
    parents << obj
  end
end
#p parents

result = {}
parents.each {|klass| result[klass.to_s] = [] }

ObjectSpace.each_object do |obj|
  parents.each do |cls|
    if obj.class == Class and obj.superclass == cls
      #puts "child of #{cls}:  #{obj}"
      result[cls.to_s] << obj.to_s
    end
  end
end

require 'pp'
pp result

s = []
s << "<variablelist>" #<title>Undtagelser</title>"
result.keys.sort.each do |parent|
  childs = result[parent]
  s << "<varlistentry><term><exceptionname>#{parent}</exceptionname></term>"
  s << "<listitem><para>"
  if childs.empty?
    s << "Ingen undtageler er afledt heraf."
  else
    s << (childs.sort.map{|name| "<exceptionname>#{name}</exceptionname>"}.join(", ") + ".")
  end
=begin
  s << "<itemizedlist>"
  s += childs.sort.map do |name|
    "<listitem><para>#{name}</para></listitem>"
  end
  s << "</itemizedlist>"
=end
  s << "</para></listitem></varlistentry>\n"
end
s << "</variablelist>"
File.open("ruby_exceptions.xml", "w+") do |file|
  file.write s.join("\n")
end
server>