From: "David A. Black" Date: 2003-12-01T02:33:30+09:00 Subject: Re: Class-level readers and writers Hi -- On Mon, 1 Dec 2003, T. Onoma wrote: > I'm actually starting to get dizzy 8-o. It would help, I think, if we lay > this down cold for all to understand. Could you fix the following yummy > class, to the best of your knowledge: > > class ClassVariableSoup > class_local_var # scope is ? > def variables > local_var # scope is method > @class_instance_var # scope is instance/ancestry I think the definitive category is really just @instance_var, with the question of whether the instance is a Class or not being irrelevant (at least pre-2.0... see below). > @_local_class_instance_var # scope is instance > @@class_var # scope is class+instance/ancestry > @@_local_class_var # scope is class+instance > # others ? > end > $global_var # scope if everywhere > end My current understanding, subject to correction, is: local => current lexical scope @instance => visible only when 'self' is what 'self' was at the time the variable was created @_instance => (2.0) visible to original 'self' (as above) and, if original 'self' was a Class, to subclasses of that class @@class => class hierarchy, including inside instance method definitions => (2.0) local to class where it's defined; still visible inside instance method definitions but not in subclasses (Note: for 2.0, which is @var and which is @_var hasn't been decided.) My least favorite of all of the proposed changes is definitely the @var/@_var thing. It means that, for the first time, the concept of an instance variable will not be completely unified. At the very least, I don't think something should be called an "instance variable" if it isn't private to the instance. (And then there's that underscore.... :-) David -- David A. Black dblack@wobblini.net