I've been looking at some articles that say that class variables are bad in Ruby. They suggest using the meta-class (or singleton class). This is my sample code
class Joe
class << self # here we're putting methods in Joe's "meta class"
attr_accessor :foo
end
def self.foo2
end
def self.foo2=value
end
end
puts Joe.singleton_methods
I understand that foo and foo2 are essentially the same, though there's no way to use attr_accesor with foo2.
I don't get what's up with the class << self syntax
. Is there some kind of concatenation happening, or... what is it? Is that some kind of extension, inheritance or monkey-patching?
Edit (Bonus): While I'm here, is there any way to cache data on a view helper? I have tried using this class << self thing, but the helper methods do not find the accessor.