First of all there is a difference between
@@var
and
@var
@@var is a class variable that is the same in all instances of a class.
@var is an instance variable that is bound to an instance of a class.
Little example:
class MyClass
@inst_var
@@cls_var
def initialize(a, b)
@inst_var = a
@@class_var = b
end
end
myobject1 = MyClass.new(1, 2)
puts myobject1.inst_var # gives 1
puts myobject1.cls_var # gives 2
myobject2 = MyClass.new(3, 4)
puts myobject2.inst_var # gives 3
puts myobject2.cls_var # gives 4
puts myobject1.inst_var # gives 1
puts myobject1.cls_var # gives 4!!!
A class variable in Ruby is like a static variable in C#.
Hope this helps a bit in understanding the difference.