From: Joel VanderWerf Date: 2002-06-07T05:17:16+09:00 Subject: Re: Returning an instance from a different class from new Jos Backus wrote: > > [For some reason I am no longer subscribed to ruby-talk and I don't get any > mail back from the ctl address, which is why I have to use my provider's > crappy newsserver :-(] > > How do I make the following return Bar instead of Foo? > > class Foo DEL>def initialize(sel) def self.new(sel=nil) > case sel > when "1" > return Bar.new > when "2" > return Baz.new when nil super() > end > end > end > > class Bar < Foo DEL>def initialize DEL> self DEL>end > end > > class Baz < Foo DEL>def initialize DEL> self DEL>end > end > > o = Foo.new("1") > p o.type