When you write this:
class Dog
@x
end
you create what's called a 'class instance variable', and you access it
like this:
Dog.x = 10 #setter
puts Dog.x #getter
However, just like with regular instance variables, you have to define
the accessor methods in order to be able to access the 'class instance
variable':
class Dog
@dog
def Dog.x=(val)
@x = val
end
def Dog.x
@x
end
end
Dog.x = 10
puts Dog.x
--output:--
10
@ variables attach themselves to whatever self is at the moment. Inside
a class, but outside any defs, self is equal to the class. Inside a
def, self is equal to the object that called the method.
--
Posted via http://www.ruby-forum.com/.