From: Rick DeNatale Date: 2008-02-29T01:12:34+09:00 Subject: Re: Abstract class On 2/28/08, Florian Gilcher wrote: > On Feb 28, 2008, at 11:54 AM, Ayyanar Aswathaman wrote: > > > How to create the abstract class and abstract method in ruby. > > In RAILS active_record::base there is an attribute abstract_class. > > How it is related to the ruby abstract class?> Don't think of this as a "true" abstract class. > > It is a value that ActiveRecord uses to determine whether a child of > ActiveRecord::Base is a "true" model (and by that, has a database > table attached to it). This is not a language feature. Yes, it's very much an ActiveRecord thing. There are three different uses of building an inheritance hierarcy for ActiveRecord models: 1) For using "single table inheritance" an ActiveRecord class and it's subclasses all need to map to the same database table. AR does this by mapping each class to a table based on it's highest non-abstract ancestor or itself if it's superclass is itself abstract. 2) For providing common setup of multiple tables. One common use of this is when you have multiple databases, with some tables in one and some in another. Making an 'abstract' ActiveRecord class for tables in a particular database to subclass, and setting the abstract class' database connection is the standard way to do this. 3) Providing common methods. However, this is almost always better achieved by using Ruby modules rather than inheritance. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/