From: Josh Cheek Date: 2011-05-23T02:11:57+09:00 Subject: Re: Ruby Clasess --e0cb4e88758f49172404a3e0731a Content-Type: text/plain; charset=ISO-8859-1 class Animal def self.inherited(subclass) children << subclass end def self.children @children ||= [] end def self.descendants children.map do |child| [child].concat child.descendants end.flatten end end Dog = Class.new Animal Cat = Class.new Animal Tabby = Class.new Cat RUBY_VERSION # => "1.9.2" Animal.children # => [Dog, Cat] Animal.descendants # => [Dog, Cat, Tabby] Cat.descendants # => [Tabby] --e0cb4e88758f49172404a3e0731a--