From: Joshua Collins Date: 2009-03-31T07:11:39+09:00 Subject: Re: When to use instance variables @ --00151750ddaa803dcd04665d5e51 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable [quote]This is not true when using class variables (@@). These need to be "declared" at the beginning of the class:[/quote] You are incorrect. On Mon, Mar 30, 2009 at 6:05 PM, I=F1aki Baz Castillo wrote= : > El Martes 31 Marzo 2009, Albert Schlef escribi=F3: > > In Ruby you declare nothing. (That's unlike languages like Java, C, > > etc., where everything has to be declated before use.) > > This is not true when using class variables (@@). These need to be > "declared" > at the beginning of the class: > > > class KK > > @@koko # <-- WRONG since no assignement is done. > # @@koko =3D #SOMETHING# is required. > > def show_var > puts "koko =3D #{@@koko}" > end > > def set_var(v) > @@koko =3D v > end > > end > > > irb(main):022:0> k=3DKK.new > > irb(main):023:0> k.show_var > NameError: uninitialized class variable @@koko in KK > > irb(main):024:0> k.set 123 > irb(main):025:0> k.show_var > koko =3D 123 > > > -- > I=F1aki Baz Castillo > > --00151750ddaa803dcd04665d5e51--