Replacing class variables
There are a few features in Ruby you should never use, and class variables are one of them. Class variable semantics are bad enough that the Ruby core team now recommends against their use, and no longer considers it worth it to even fix bugs in how class variables are handled. This is a shame because class variables almost have behavior you want. However, class variable behavior is just different enough from what you want to not be useful.
At first appearance, class variables have desirable qualities:
- You can access them in the class itself.
- You can access them when reopening the singleton class in the class itself.
- You can access them in the class's methods.
- You can access them in all of these places in any of the class's subclasses.
Here's an example:
class A   @@a = 1   class << self     @@a   end   def b     @@a  ...