Given the code below:
class Man
def self.noise=(noise)
@@noise = noise
end
end
puts Man.noise = ("YO")
I have used the setter method self.noise, but not actually used the getter method and it worked. I'm curious to know whether class variables requires getter and setter methods to work?
The confusing element in all of this is that instance variables seem to need both getter and setter methods to be accessed. If you only have a setter method to access instance variables, the variable simply will not get returned, if you call the setter method.
My question is that for class variables, can you only have a setter method and call it, without a getter method to access the class variable? In this case, the getter method would be:
self.noise
@@noise
end