module NRSER::Meta::ClassAttrs

Mixin to provide methods to define and access class attributes - variables that act like instance variables with regards to inheritance but for the class itself.

The motivation is to create a easy-to-use class instance variables that resolve like regular instance variables by looking up the inheritance hierarchy - meaning that:

  1. When the value is set, it is set on the class in which the operation happens.

  2. That value is read for that class and any subclasses.

    • Class 'self' attr_accessor values are not visible to subclasses.

  3. But that value is not visible to any classes further up the inheritance chain.

    • Class variables (`@@` variables) are global to the *entire class hierarchy* rooted at the definition point.

The tests in `spec/nrser/class_attrs_spec.rb` provide detailed walk-through of usage and differences from other approaches.

Public Class Methods

included(base) click to toggle source

Extend the including class with {NRSER::Meta::ClassAttrs::ClassMethods}

# File lib/nrser/meta/class_attrs.rb, line 116
def self.included base
  base.extend ClassMethods
end