From: Ron Jeffries Date: 2002-03-17T10:58:25+09:00 Subject: Re: Could we subclass this way? On 16 Mar 2002 14:30:35 -0800, hubert@cs.nyu.edu (Hubert Hung-Hsien Chang) wrote: >I would like to have @vampire_tricks, @ghost_tricks respectively. >But I wuld still like to use the Monster's methods. And both >@vampire_tricks and @ghost_tricks will refect the value >of @tricks from "Monster" > > >I haven't successfully done it easily. Any way out? I'm not sure what you're trying to do, but if you go ahead and define the variables separately, and implement an accessor method in each class: class Monster def tricks return @tricks end end class Vampire < Monster def tricks return @vampire_tricks end end and so on, that might get you along the way. If all monsters of a given class have the same kind of tricks, the tricks might want to be class variables instead of instance variables. and if there can be instances of Monster as well as Vampire and Ghost, it might be better to create an "abstract superclass" to serve as the superclass of all three. Good luck, and lock your door before going to sleep. Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.