From: Adelle Hartley Date: 2005-03-26T18:42:54+09:00 Subject: Re: Instead of templates Hi Mathieu, > class A > @special={} > def self.of(t) > @special[t] ||= Class.new(self) { @mytype=t; ... } > end > end That's a neat idea. I think I will keep that up my sleeve. I am bound to need it. > > Where "..." may be any specialisation-specific code, e.g. an > eval that recreates some methods in a speed-optimised way > depending on t. > > Does that make sense? > > However I have no experience combining regular inheritance > and this technique, and I know this technique may be > difficult to combine with regular inheritance in a way that > makes it really closer to C++. Your technique already combines regular inheritance - all of your A.of(t) classes inherit from A, so any method defined in A will be inherited by A.of(t). My question (and Robert gave a good answer on how to do this) was one degree more complicated because I not only wanted the child classes to have their own implementation but wanted any classes that inherit from *them* to have their own implementation as well. > Btw, what's the class A< either class A