Method: RubyXL::OOXMLObjectClassMethods#obtain_class_variable
- Defined in:
- lib/rubyXL/objects/ooxml_object.rb
permalink #obtain_class_variable(var_name, default = nil) ⇒ Object
Get the value of a [sub]class variable if it exists, or create the respective variable with the passed-in default
(or {}, if not specified)
Throughout this class, we are setting class variables through explicit method calls rather than by directly addressing the name of the variable because of context issues: addressing variable by name creates it in the context of defining class, while calling the setter/getter method addresses it in the context of descendant class, which is what we need.
15 16 17 18 19 |
# File 'lib/rubyXL/objects/ooxml_object.rb', line 15 def obtain_class_variable(var_name, default = nil) self.class_variable_get(var_name) rescue NameError self.class_variable_set(var_name, default || {}) end |