From: Eric Hodel Date: 2003-11-06T13:29:33-08:00 Subject: Re: Inheritence Diagram of Ruby classes... --jaTU8Y2VLE5tlY1O Content-Type: multipart/mixed; boundary="4C6bbPZ6c/S1npyF" Content-Disposition: inline --4C6bbPZ6c/S1npyF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Thomas Adam (thomas_adam16@yahoo.com) wrote: > Thank you ever so much for that, but do you have the script? Only, It > wasn't attached to the e-mail :) Dang, oops! Here it is, no really. --=20 Eric Hodel - drbrain@segment7.net - http://segment7.net All messages signed with fingerprint: FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04 --4C6bbPZ6c/S1npyF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="x.rb" Content-Transfer-Encoding: quoted-printable klasses =3D [] class ClassNode @@nodes =3D {} attr_accessor :val, :children def initialize(val) @val =3D val @children =3D [] end def walk_children(level, &block) block.call("#{' '*level}#{@val}\n") level +=3D 1 children.sort { |a, b| a.name <=3D> b.name }.each do |child| node =3D @@nodes[child] unless node.nil? then node.walk_children(level, &block) else block.call("#{' '*level}#{child}\n") end end end def self.add(node, parent) if @@nodes.has_key? parent then @@nodes[parent].children << node else @@nodes[parent] =3D ClassNode.new(parent) @@nodes[parent].children << node end end def self.tree(root =3D Kernel) rv =3D "" @@nodes[root].walk_children(0) do |s| rv << s end return rv end end ObjectSpace.each_object(Class) do |klass| ancestor =3D nil klass.ancestors[1..-1].each do |a| if a.kind_of? Class or a =3D=3D Kernel then ancestor =3D a=20 break end end klasses << [klass, ancestor] end klasses.each do |klass, ancestor| ClassNode.add(klass, ancestor) end puts ClassNode.tree --4C6bbPZ6c/S1npyF-- --jaTU8Y2VLE5tlY1O Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (FreeBSD) iD8DBQE/qr09MypVHHlsnwQRAiYDAJ49Tl/EqrHHyQNICJOl0Y12k+HjGACfUoQG /73jLbSqO0q9O4qKQ8rCYjQ= =jDhZ -----END PGP SIGNATURE----- --jaTU8Y2VLE5tlY1O--