From: Dan Debertin Date: 2002-08-27T12:32:54+09:00 Subject: Re: proxy class / little factory --Multipart_Mon_Aug_26_22:32:39_2002-1 Content-Type: text/plain; charset=US-ASCII At Tue, 27 Aug 2002 12:01:25 +0900, Tom Sawyer wrote: > > 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 Hmmm ... this seems like a perfect spot for forwardable.rb to me: require "forwardable" class Text extend Forwardable def initialize(component) if(component <= 1) @proxy = TextSingle.new else @proxy = TextMultiple.new end end def_delegator(:@proxy, :meth) class TextSingle def meth puts "I'm from TextSingle!" end end class TextMultiple def meth puts "I'm from TextMultiple!" end end end --Multipart_Mon_Aug_26_22:32:39_2002-1 Content-Type: text/plain; charset=US-ASCII -- /^Dan Debertin$/ airboss@nodewarrior.org | Did I sleep a little too late, www.nodewarrior.org | or am I awake? --Byrne --Multipart_Mon_Aug_26_22:32:39_2002-1 Content-Type: text/plain; charset=US-ASCII -- /^Dan Debertin$/ airboss@nodewarrior.org | Did I sleep a little too late, www.nodewarrior.org | or am I awake? --Byrne --Multipart_Mon_Aug_26_22:32:39_2002-1--