From: Dave Thomas Date: 2003-05-15T12:48:33+09:00 Subject: 1.8-intense class tree I was trying to come up with some example code for 'prettyprint' and I remembered Hal's class diagram. This is somewhat ugly in the details, but it does show some 1.7/1.8 features: prettyprint, Hashes with blocks for unknown values, and Enumerable#sort_by. Cheers Dave require 'prettyprint' @children = Hash.new { |h,k| h[k] = Array.new } ObjectSpace.each_object(Class) { |cls| @children[cls.superclass] << cls} def print_children_of(pp, cls) pp.group do pp.text(cls.name) pp.group do kids = @children[cls].sort_by {|k| k.name} unless kids.empty? pp.text ' [' pp.nest(3) do pp.breakable kids.each do |k| next if k == Exception || k.name =~ /^Pretty/ unless pp.first? pp.text ',' pp.breakable end print_children_of(pp, k) end end pp.breakable pp.text ']' end end end end pp = PrettyPrint.new($stdout, 40) print_children_of(pp, Object) pp.flush puts