From: 7stud -- Date: 2011-04-19T03:24:32+09:00 Subject: Re: Making a simple parser I'm pretty unclear about what you are trying to do, but maybe this will help: class InputFormat @children = [] def self.children @children end def initialize(input) @input = input end def parse InputFormat.children.each { |child| child.parse(@input) if child.supported? } end def self.inherited(sub_class) @children << sub_class.new('dummy') end end class InputFormatA < InputFormat def supported? true end def parse(str) puts "InputFormatA is parsing #{str}" end end class InputFormatB < InputFormat def supported? true end def parse(str) puts "InputFormatB is parsing #{str}" end end input = InputFormat.new('hello world') input.parse --output:-- InputFormatA is parsing hello world InputFormatB is parsing hello world Note that when inherited() is called, the methods of the subclass are not defined yet, so the inherited initialize() is called. -- Posted via http://www.ruby-forum.com/.