From: Pit Capitain Date: 2005-12-06T17:30:43+09:00 Subject: Re: Subclassing Class. John Carter schrieb: > > On to the next step. Let's rename Foo to AbstractFoo > > Now I wanted > class AbstractFoo < Class > end > > and you have given me that. But that was merely the first step in my > agenda. > > I actually also want.... > class ConcreteFooClass < AbstractFooClass > end > > class OtherConcreteFooClass < AbstractFooClass > end > that polymorphically inherits behaviour from AbstractFooClass. John, I'm not sure what you really need, but I think that the singleton class approach that others have suggested gives you the desired behaviour: class Foo def self.new fu, stuff super "#{fu} and #{stuff}" end def initialize things puts "new Foo with #{things}" end end Foo.new "abstract fu", "abstract stuff" # => new Foo with abstract fu and abstract stuff class ConcreteFoo < Foo def self.new fu super fu, "concrete stuff" end def initialize things print "ConcreteFoo: " super end end ConcreteFoo.new "concrete fu" # => ConcreteFoo: new Foo with concrete fu and concrete stuff The class ConcreteFoo inherits behaviour from the class Foo and ConcreteFoo's singleton class inherits from Foo's singleton class. I don't know whether this still works in Ruby 1.9, though. Regards, Pit