Consider this code:
class Polygon
@sides=1
@@sides = 10
class << self; attr_accessor :sides end
def self.sides
@@sides
end
end
If I print sides:
p Polygon.sides
I get 10. If I change the order of class and self.sides, I will get 1. What is the cause of this behaviour? How can I call the @@sides or @sides independently of the order of the methods?
edit
I found this excellent post that discuss the difference between class variables, class instance variables and instance variables.