I thought I might share this little piece of code that generates a
'lstree'-like output for class-hierarchy:

> lstree(Numeric)

- Numeric
    |- Float
    `- Integer
        |- Bignum
        `- Fixnum

Of course it is meant to be run for you own class hierarchies. It's
basic stuff but I couldn't find anything like it anywhere ...


Cheers,
Simon


_CODE:_

#!/usr/bin/ruby -w
#
# A class inheritance tree generator
#


def lstree(root)
  # get children of root
  children = Hash.new()
  ObjectSpace.each_object(Class) do |aClass| 
    if (root != aClass && aClass.ancestors.include?(root))
      children[aClass.superclass] = Array.new() if children[aClass.superclass] == nil
      children[aClass.superclass].push(aClass)
    end
  end

  # print nice ascii class inheritance tree
  recursePrint = proc {|current_root,prefixString|
    puts(prefixString+"- "+current_root.to_s)
    if children[current_root] != nil
      children[current_root].each do |child|
          recursePrint.call(child,prefixString.tr('`',' ') + "    "+(child == children[current_root].last ? "`":"|"))
      end
    end
  }

  recursePrint.call(root,"")
end



-- 
There are 10 types of people in the world... 
those who understand binary and those who don't.