From: Ceri Storey Date: 2003-11-25T23:26:58+09:00 Subject: Class#inherited, class definition and industry. --GvXjxJ+pjyke8COw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi there. Am I correct in thinking that the #inherited method of the parent class is called *before* the body of the class is evaluated? If so, is there a more sensible way of working around this, than something like the following? -- Ceri Storey --GvXjxJ+pjyke8COw Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="sample.rb" class Builder @registry = {} @registered = [] class << self def inherited(sub) @registered.push(sub) end def lookup(name) if @registry.include?(name) @registry[name] elsif c = @registered.find { |c| c.name == name } @registry[c.name] = c c else raise "No such Class" end end def create(name, *args) lookup(name).new(*args) end end end class Moogle < Builder class << self def name "moogle" end end end Builder.create("moogle") --GvXjxJ+pjyke8COw--