[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Instance- and class-variables (was Re: mixing in class methods

dblack

10/2/2003 12:46:00 PM

3 Answers

Mark J. Reed

10/2/2003 1:49:00 PM

0

The assymetry between class/instance variables and class/instance
methods has always bothered me. It seems to me that it would
make more sense for class variables to be the same as instance
varaibles of the class object. That is:

class Foo
@@var = 1
class << self
# @var here should refer to @@var
...
end
end

This was, indeed, what I expected to be the case upon my first
exposure to these Ruby concepts. But instead, there are effectively
three categories of variable instead of two, and the @@ category seems to
me to behave very oddly.

Guess this is just another case where the principle-of-least-surprise-to-Matz
is not the same as the principle-of-least-surprise-to-Mark. :)

-Mark

ts

10/2/2003 2:10:00 PM

0

>>>>> "M" == Mark J Reed <markjreed@mail.com> writes:

M> This was, indeed, what I expected to be the case upon my first
M> exposure to these Ruby concepts. But instead, there are effectively
M> three categories of variable instead of two, and the @@ category seems to
M> me to behave very oddly.

No, no : there are only 2 categories.


Guy Decoux

Mark J. Reed

10/2/2003 2:19:00 PM

0

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.

-Mark