Given the Ruby code below, can someone help me understand the different use cases between @v and @@w? I understand that the class C is an object of the class Class, and because of this, @v is an instance variable of the class C object.
class C
@v = "I'm an instance variable of the class C object."
puts @v
@@w = "I'm a class variable of the class C."
puts @@w
end
Instance Variable’s scope is just limited to the object of the Class. For eg. If you intantiate the Class C by creating an object then you have the access to @v.
Where as The Class Variables span through out the class i.e. they are also visible to the instances of the Classes(ie Objects) and other class methods.
Related Reading:
Difference between class variables and class instance variables?
http://www.railstips.org/blog/archives/2006/11/18/class-and-instance-variables-in-ruby/