From: Joel VanderWerf Date: 2003-04-08T09:54:58+09:00 Subject: Re: @@class variables and subclasses Ryan Pavlik wrote: > OK, this has been causing me problems: > > class A > @@index = Index.new(...) > end #c:A > > > class B < A > @@index = Index.new(...) > end #c:B > > This has the unfortunate problem of causing @@index in class A to be > replaced with the new one in class B, because @@class variables are > shared between classes. This is annoying. In some cases I can use > @instance variables for a class, but in this case I need to access the > class index (@@index) in instance methods, and it's not an instance > variable. (I can't access class @instance variables from instance > functions that I know of.) > > Ideas? > This is one approach, but it makes everything public, unlike @@index. (You could make the attr_accessor protected, though.) class A class <