[HELP] : about class variables

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,

···

--------------
Sebastien

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

···

On Mon, 12 Jul 2004, kurk_lord@yahoo.fr wrote:

--
David A. Black
dblack@wobblini.net

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:

class Foo
@@toto=20
def self.toto
  @@toto
end
end

=> nil

Foo.toto

=> 20

hope this helps

···

il Sun, 11 Jul 2004 21:46:06 +0200, "kurk_lord@yahoo.fr" <kurk_lord@yahoo.nospam.fr> ha scritto::

kurk_lord@yahoo.fr 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,

--------------
Sebastien

Thanks guys. It works so good.

···

--------------
Sebastien