Hello,
I believe there is a need in class_attr methods collection.
We all know the attr collection:
attr_reader :my_var
attr_writer :my_other_var
attr_accessor :my_best_var
They create those methods:
def my_var
@my_var
end
def my_other_var=(value)
@my_other_var = value
end
But there are also class variables:
class MyClass
@a = "value"
def self.a
@a
end
end
puts Test.a # it works
It would be easier to write it this way:
class MyClass
@a = "value"
class_attr_reader :a
end
puts Test.a # it doesn't work
I know class variables are already accessible through @@a. But it violates some OO principles: as the class itself is an object, it allows another object (its instances) to access its internals. Ruby forbid this for normal objects, why then allowing this for class objects?
It may have changed, but I believe '@@' will disapear in ruby2 because of that violation. That's why I try myself to get used in avoiding the use of '@@'. And that's why I've realised the need for class_attr methods collection.
Any opinions?
Regards,
Lionel Thiry