From: Simon Strandgaard Date: 2004-04-15T19:29:21+09:00 Subject: Re: ObjectGraph: a Ruby class inheritance hierarchy graph 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 << "" #Undtagelser" result.keys.sort.each do |parent| childs = result[parent] s << "#{parent}" s << "" if childs.empty? s << "Ingen undtageler er afledt heraf." else s << (childs.sort.map{|name| "#{name}"}.join(", ") + ".") end =begin s << "" s += childs.sort.map do |name| "#{name}" end s << "" =end s << "\n" end s << "" File.open("ruby_exceptions.xml", "w+") do |file| file.write s.join("\n") end server>