sayoyo
April 25, 2006, 6:26pm
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.
Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...
sayoyo
April 25, 2006, 10:26pm
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. "
sayoyo
April 25, 2006, 10:52pm
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.