From: Niklas Frykholm Date: 2001-11-11T20:14:10+09:00 Subject: [ruby-talk:24872] Re: Help needed on subclassing [Robert Feldt]: > Its late here in Sweden (actually early, but anyway... ;-)) and I cant > find an elegant way to from class M subclass class T so that in > the subclass some (but not all) of the arguments for T.new are specified. > > Example: > T is class with T.new(a,b,c) > M.[] needs to return a subclass of T (lets call it S) so that calls > S.new(c) are translated to T.new(am,bm,c). 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 // Niklas