How can I access a class variable outside of the class?


#1

Hi

we wanted to access a class varaible from outside of
the same class, like

class klass
@@var1
end

we found out we can not use the class variable like
this:
klass.var1 we have to create a class function like

class klass
@@var1

def var1
return @@var1
end

end

If anyone know how to access a class variable directly
without passing by a function???

Thanks you very much

Saiho

The mind is its own place, and in itself.
Can make a Heaven of Hell, a Hell of Heaven.

http://www.geocities.com/sayoyo/


Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


#2

From picaxe book:

" Class variables are private to a class and its instances. If you want
to
make them accessible to the outside world, you’ll need to write an
accessor
method. This method could be either an instance method or, leading us
neatly
to the next section, a class method. "


#3

Saiho sayoyo wrote:

Hi

we wanted to access a class varaible from outside of
the same class, like

class klass
@@var1
end

Try

cattr_accessor :some_var

works just like attr_accessor except for class variables.