From: jos@... (Jos Backus) Date: 2002-06-07T08:33:34+09:00 Subject: Re: Returning an instance from a different class from new In article <20020606205418.GA4313@digikata.com>, Alan Chen wrote: >I would recommend breaking out the functionality in >Foo's initialize into a factory function. Thanks, I understand this example (I think): module FooFactory def build(sel, field) case sel when "1" return Bar.new(field) when "2" return Baz.new(field) end end end include FooFactory class Foo attr_accessor :field def initialize(field) @field = field end end class Bar < Foo def initialize(field) super end end class Baz < Foo def initialize(field) super end end o = FooFactory.build('1', "field1") p o.type, o.field o = FooFactory.build('2', "field2") p o.type, o.field -- Jos Backus _/ _/_/_/ Santa Clara, CA _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ jos@catnook.com _/_/ _/_/_/ use Std::Disclaimer;