Hi --

On Sat, 4 Jul 2009, dzw! wrote:

> Ok, code below shows better what I am talking about, I understand that
> @@var is acting like global variable.
> But how to get rid of it when is not needed anymore?

[...]

> A.item =>  "var in A"
> B.item =>  "var in B"
>
> A.item='test'
>
> A.item =>  "test"
> B.item =>  "var in B"
>
> @@var ='ltl fkr'                #here is the funny part
>
> A.item         => "ltl fkr"
> B.item         => "ltl fkr"
>
> A.item='test'                  #and here is getting even funnier
>
> A.item         => "test"
> B.item         => "test"    # i wish it to stay 'ltl fkr'

You're trying to maintain and alter state on a per-class basis, which
really means on a per-object (class object) basis. Class variables are
not suited to that purpose; they are, as you say, really sort of
vertical globals.

(In fact, I've always thought that $$var would be a better designation
for class variables than @@var, because @@var makes it look like class
variables have some kind of affinity with instance variables, which
they definitely don't.)

Anyway -- I don't know of any way to undefine a class variable. I'd
recommend using instance variables if you need per-class state.


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Now available: The Well-Grounded Rubyist (http://manning.com/black2)
Training! Intro to Ruby, with Black & Kastner, September 14-17
(More info: http://rubyurl.com/vmzN)