From: Todd Benson Date: 2008-02-08T18:44:53+09:00 Subject: Re: Multilevel class inheritance not working as expected On Feb 8, 2008 3:10 AM, Jörg Battermann wrote: > Hello there, > > I am having a problem inheriting an already inherited class. errr.. > sounds more complicated than it is.. look: > > class Item < ActiveRecord::Base > # has a name and description field > end > > class Reference < Item > # has a something field > end > > class UrlReference < Reference > #has an url field > end > > ... now If I do make a u = UrlReference.new in the console for > example, the 'u' instance does NOT have the url field.. only the ones > from Reference and Item... > > > How come? I guess that's basic ruby.. but how do I properly inherit > from other classes which again inherit from other ones? Did I miss > something here? > > Cheers & thanks, Hmm, not sure. I think maybe the problem lies within your database schema or your use of "single table inheritance" with ActiveRecord. Class inheritance in pure Ruby is easy... class A def initialize; @a=nil; end end class B < A def initialize; super; @b=nil; end end class C < B def initialize; super; @c=nil; end end c = C.new puts c.inspect => # Todd