Max Ischenko wrote:
> class A
>         @@VAR = {'A'=>1}
> 
>         def initialize
>                 puts @@VAR
>         end
> end
> 
> class C < A
>         @@VAR = {'C'=>1}
> end
> 
> class B < A
>         @@VAR = {'B'=>1}
> end

From your expectations, you're basically assuming that each class has
its own set of variables, that aren't touched by subclasses. That isn't
exactly how it goes in Ruby (nor in Java for that matter). The fact that
the last @@VAR is the one kept, is mearly because every line is a
statement in Ruby.

How about this case?
<CODE>
class Car
	@@NUM_CARS = 0
	def initialize
		@@NUM_CARS = @@NUM_CARS +  1
		puts @@NUM_CARS
	end
end
class SportsCar < Car
end
class FamilyCar < Car
end

a = Car.new
b = SportsCar.new
c = FamilyCar.new
</CODE>

Here I'm using the class variable to keep track of the total number of
cars created, nomatter the type. But you appear to expect a separate
variable for each subclass. I think you'll have to use different names
for them to get what you want, but I don't think that class variables
are the correct thing for what you are trying to do. 

<CODE>
class Car
	@@NUM_CARS = 0
	def initialize
		@@NUM_CARS = @@NUM_CARS +  1
		puts "Cars: " + @@NUM_CARS.to_s
	end
end

class SportsCar < Car
        @@NUM_SPORTS_CARS = 0
	def initialize
                super
		@@NUM_SPORTS_CARS = @@NUM_SPORTS_CARS +  1
		puts "SportsCars:" +  @@NUM_SPORTS_CARS.to_s
	end
end

class FamilyCar < Car
end

a = Car.new
b = SportsCar.new
c = FamilyCar.new
</CODE>

As for an attempt at accomplishing what you were after, try this hack:
<CODE>
class A
        @@A_VAR = {'A'=>1}

        def A.getVAR     #dynamic method calling on the class object
itself
                @@A_VAR
        end

        def A.new
                 puts getVAR
        end

        def initialize
        end

 end
 
 class C < A
         @@C_VAR = {'C'=>1}
        def C.getVAR
                @@C_VAR
        end

 end
 
 class B < A
         @@B_VAR = {'B'=>1}
        def B.getVAR
                @@B_VAR
        end
 end

b=B.new
c=C.new
a=A.new
</CODE>


-- 
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
  )____(stud.techn.;ind..data)||(softwareDeveloper.at(Trustix))_( 
 /"Opinions expressed are mine and not those of my Employer,      "\
( "the University, my girlfriend, stray cats, banana fruitflies,  " )
 \"nor the frontal lobe of my left cerebral hemisphere.           "/