From: Philipp Meier Date: 2002-09-04T00:53:17+09:00 Subject: Class variables and inheritance --H+4ONPRPur6+Ovig Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hallo rubyers, I'm a little puzzled with Class variables (@@foo) and inheritance: class Super @@foo =3D [] def self.manipulate(arg) @@foo << arg end def get_foo @@foo end end class Sub1 < Super manipulate "first" end class Sub2 < Super manipulate "second" end Sub1.new.get_foo # =3D> ["first","second"], wanted "first" Sub2.new.get_foo # =3D> ["first","second"], wanted "second" I know that Class variables a tied to the class they are defined in but how can I make @@foo belong to Sub1 / Sub2 without explicitly declaring it there?=20 I tried append_features which worked partly: module Super def self.append_features(klass) class << klass @@foo =3D [] def manipulate(arg) @@foo << arg end end end end class Sub1 include Super end But then, how can a declare an instance method? I don't like to do both inheritance and including a Mixin which should work at the end: class Sub1 < SuperClass include SuperModule end Any help is appreciated. -billy. --=20 Meisterbohne S=F6flinger Stra=DFe 100 Tel: +49-731-399 499-0 eL=F6sungen 89077 Ulm Fax: +49-731-399 499-9 --H+4ONPRPur6+Ovig Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (GNU/Linux) iD8DBQE9dNiIfBriNoqItSYRAjJsAKCKZx+F7F+NmFBST5G7eVB+2qB5HwCglNdz l+SIbZ3ZiIblIrZGJYnIvZU= =V+qR -----END PGP SIGNATURE----- --H+4ONPRPur6+Ovig--