From: Robert Klemme Date: 2007-11-08T22:08:24+09:00 Subject: Re: alternate to case; generating a list of sub-classes 2007/11/8, Thufir : > The below uses pseudo-random number generation to populate an array > with various monsters, all inherit from Creature. Can a list of > classes which inherit from Creature be generated automagically? There > must be a better technique to fill the array then the case > statement... I usually do this when I want to also recursively track subclasses: module Hierarchy def inherited(cl) superclass.instance_eval { inherited cl } (@children ||= []) << cl cl.extend Hierarchy end attr_reader :children end class Foo extend Hierarchy end class Bar < Foo end class Dice < Bar end p Bar.children p Foo.children Cheers robert -- use.inject do |as, often| as.you_can - without end