[HELP] : about class variables

K

kurk_lord

Hi all,

in ruby class variables are private. Who know to do
for making them accessible to the outsite world. I
am looking for to do something like in Java :

Toto.count

Toto is my class and count is my class variable.

Thanks all,
 
D

David A. Black

Hi --

Hi all,

in ruby class variables are private. Who know to do
for making them accessible to the outsite world. I
am looking for to do something like in Java :

Toto.count

Toto is my class and count is my class variable.

You could do:

class Toto
def Toto.count
@@count
end
end

As an Object, a Class is also entitled to have its own instance
variables. So you also use @count in the above, rather than @@count.
(And actually @count has some advantages, in terms of scope. It
actually *more* private to the class -- but still can be made visible
through a method, if the class wants it to be.)


David
 
G

gabriele renzi

il Sun, 11 Jul 2004 21:46:06 +0200, "(e-mail address removed)"
Hi all,

in ruby class variables are private. Who know to do
for making them accessible to the outsite world. I
am looking for to do something like in Java :

Toto.count

Toto is my class and count is my class variable.

you use accessors:
=> 20

hope this helps
 
K

kurkLord

(e-mail address removed) a écrit :
Hi all,

in ruby class variables are private. Who know to do
for making them accessible to the outsite world. I
am looking for to do something like in Java :

Toto.count

Toto is my class and count is my class variable.

Thanks all,

Thanks guys. It works so good.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,837
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top