Module: NRSER::Meta::ClassAttrs

Defined in:
lib/nrser/meta/class_attrs.rb

Overview

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.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Extend the including class with ClassMethods



116
117
118
# File 'lib/nrser/meta/class_attrs.rb', line 116

def self.included base
  base.extend ClassMethods
end