From: dblack@... Date: 2003-10-03T00:29:17+09:00 Subject: Re: Instance- and class-variables (was Re: mixing in class methods) Hi -- On Thu, 2 Oct 2003, Mark J. Reed wrote: > On Thu, Oct 02, 2003 at 11:09:32PM +0900, ts wrote: > > No, no : there are only 2 categories. > > Yes, I know: @ and @@. @ variables are instance variables of an > object, and classes are really just objects. But the is-a > relationship is special, and that specialness is echoed in the > treatment of @@ variables. > > Logically, I still think it would make sense for @@vars to be > equivalent to @vars of the class. The real problem is that it > would violate encapsulation within the middle-layer implementation - > instances need to be shielded from the innards of their class objects. Also, every object should have the right to maintain state in instance variables that are not (easily) visible to other objects. Class objects should not be penalized in this regard (i.e., by having their instance variables conflated with something else) just because they are Class objects. Another way to look at it is that Matz clearly wants these two very different things to exist, so if @@var were an alias for class << self; @var; end, there would presumably be something else ($$var or ^^var or whatever) to represent class variables. So then the question would arise again: should ^^var be equivalent to class << self; @var; end, and so on infinitely. I guess the @-similarity leads more quickly to this kind of question than might be the case otherwise, but it's really just a cosmetic detail. David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav