From: Joel VanderWerf Date: 2006-12-04T05:51:34+09:00 Subject: Re: Factory pattern, abstract base class One more suggestion that allows handling of other arguments besides the class selection: module Foo class Bar def self.new(kind, *args) return super(*args) if self != Foo::Bar case kind.downcase when 'baz' return Baz.new(kind, *args) when 'zap' return Zap.new(kind, *args) end end end class Baz < Bar class << self; protected :new; end def initialize(*args) @args = args end end class Zap < Bar class << self; protected :new; end end end fb = Foo::Bar.new('baz', "arg1", 2, [3]) p fb # ==> # -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407