From: Robert Feldt Date: 2001-11-12T07:25:52+09:00 Subject: [ruby-talk:24896] Re: Help needed on subclassing On Sun, 11 Nov 2001, Niklas Frykholm wrote: > What about this? > > class T > def initialize(a,b,c) > puts "T #{a} #{b} #{c}" > end > end > > class M > def [](x) > s = Class.new(T) > class << s > def new(c) > T.new(1,2,c) > end > end > return s > end > end > > Or if you don't need S to be a real class, you could do: > > class T > def initialize(a,b,c) > puts "T #{a} #{b} #{c}" > end > end > > class SMeta > def initialize(am, bm) > @am, @bm = am, bm > end > > def new(c) > T.new(@am, @bm, c) > end > end > > class M > def [](x) > SMeta.new(1,2) > end > end > Yes, these are two good solutions to my problem. Thanks; when the brain gets cloudy and you can't see the light its good to have a community to lean on. (And its amazing how "cloudy" things can get when doing a Ruby all-nighter! :-) Seems almost like the brain gradually degrades and narrows in on some basic, low-level functions. What happened to those 40-hour weeks XP promised!? I'm trying to use XP and test-first design as much as possible. Can the problem be that I'm not a pair? :-) ) Regards, /Robert