From: nobu.nokada@... Date: 2002-08-27T12:24:16+09:00 Subject: Re: proxy class / little factory Hi, At Tue, 27 Aug 2002 12:01:25 +0900, Tom Sawyer wrote: > maybe someone can help me. i am trying to make a class such that when it > is used it acts like one or another class based on an attribute. i wrote > this little factory version: (snip) > this could work (i actually haven't run it) but the problem is that the > type of the object returned is not Text, but TextSingle or TextMultiple. > i need it to be Text. eg. > > atext = Text.new(1) > p atext.class # --> TextSingle > > for it it needs to be: > > p atext.class # --> Text > > suggestions? First, which do you want, an instance of distinct classes, or one of a particular class? What about these? ;-) class Text class TextSingle; def class; Text end end class TextMultiple; def class; Text end end end or class Text class TextSingle; def self.to_s; "Text" end end class TextMultiple; def self.to_s; "Text" end end end -- Nobu Nakada