I have a several classes that inherit from a single class:
class Bravo << Alpha
class Charlie << Alpha
Alpha has some class level variables:
class Alpha
@@terms
def initialize
...
@@terms ||= load_terms
end
end
OK, all is fine so far. But I’d like to access the class level variables from the console for troubleshooting purposes. Is this possible? I’ve tried:
# inst is an instance of Bravo for example
inst.class.superclass:terms
inst.@@terms
inst.class.superclass[:terms]
Didn’t expect any of that to really work, just grabbing at straws since I couldn’t find any answer to the question. I’ve confirmed that the class variables are there via:
>> inst.class.superclass.class_variables
=> [:terms]
OK, I can see that they are there, but is there any way to directly access them via the rails console?
You almost made it 🙂
It may look complicated, and it probably is so for a reason: to discourage people from messing with class’ internals (I don’t know if it’s true, I just made it up).
If you need this on a regular basis, add an accessor for it!