From: Daniel Schierbeck Date: 2005-11-14T21:57:16+09:00 Subject: Re: Heirarchy Troubles CBlair1986 wrote: > Hello all. I've got a somewhat unique problem, I think. I have a list > of classes planned out, with the attributes needed for them and > everything else, but I want to figure out how the classes should relate > to one another, so that I don't need to needlessly repeat myself. > > For instance, say I have the classes planned as such: > class Apple > attr_accessor :taste, :type, :flavor, :flesh, ... > end > class Orange > attr_accessor :taste, :type, :flavor, :peel, ... > end > and so on. > > How would I go about fitting these together, so that I could have more > general classes such as Fruit and Vegetable and so on? > > Thank you! > class Fruit attr_accessor :type, :taste, :flavor def initialize(type = nil, taste = nil, flavor = nil) @type, @taste, @flavor = type, taste, flavor end end class Apple < Fruit def flesh # flesh the apple end end class Orange < Fruit def peel # peel the orange end end