I thought it was possible to define attr_accessor methods in a eigenclass like this:
class IOS
@@modules_paths = "hello"
class << self
attr_accessor :modules_paths
end
end
puts IOS::modules_paths
But this returns nothing.
Is there a way to do it?
The
attr_accessoryou add to the class uses class-level instance variables, not class variables. This can actually be more helpful in some cases, since class variables can get ridiculous when inheritance enters the picture.If you really need it to use class variables, you can define the methods manually, pull in ActiveSupport and use
cattr_accessor, or just copy the relevant ActiveSupport methods.