From: Aristarkh A Zagorodnikov Date: 2001-11-11T16:56:28+09:00 Subject: [ruby-talk:24863] Re: Help needed on subclassing > -----Original Message----- > From: Bob Gustafson [mailto:bobgus@mcs.com] > Sent: Sunday, November 11, 2001 9:44 AM > To: ruby-talk ML > Subject: [ruby-talk:24860] Re: Help needed on subclassing > > > >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). > > > >Ok, you can use evals but I'd call that cheating. > > > >Please help me; my brain and screen are hazy! ;-) > > > >/Robert > > Why not do > > def T.new(a=defaulta,b=defaultb,c=defaultc) > > Except that you probably need to put the c first > > def T.new(c=defaultc, a=defaulta,b=defaultb) Using default parameters isn't any good I believe. If I understood you corrctly you'll need something like this: class T def initialize(a, b, c) ............ end end class S < T def self.new(c) super -12, "nothing more than a test string", c end end class M def [](arg) S.new 47 end end _____________________________________________________________ Zagorodnikov Aristarkh | Lead Programmer | xm@bolotov-team.ru bolotov.ru creative group http://www.bolotov.ru/