From: rbaldwin Date: 2007-12-13T09:54:59+09:00 Subject: Re: Abstract -- what's the Ruby way? On Dec 12, 5:10 pm, "Tim Rowe" wrote: > What's the Ruby way to define a class that shouldn't be instantiated, but > with descendants that can be? Other than a comment in the documentation, of > course. > > Thanks! Here is one way. Its not very satisfying, as you have no way to access the initialize method on any parent classes of the Animal class (such as ActiveRecord)... class Animal def initialize raise 'Invalid instantiation of class' end def talk puts 'hi' end end class Dog < Animal def initialize # this can be empty # don't use super here as will cause exception from Animal end end # this will fail (as it should) with an exception # a = Animal.new # this succeeds d = Dog.new d.talk