Class: SleepingKingStudios::Tools::Toolbox::HeritableData::HeritableMethods
- Inherits:
-
Module
- Object
- Module
- SleepingKingStudios::Tools::Toolbox::HeritableData::HeritableMethods
- Defined in:
- lib/sleeping_king_studios/tools/toolbox/heritable_data.rb
Overview
Custom module used to propagate heritable methods across Data classes.
Instance Attribute Summary collapse
-
#parent_class ⇒ Class?
readonly
The parent data class.
Instance Method Summary collapse
-
#each_heritable_module ⇒ Object
Iterates over the ::HeritableMethods modules for parent classes.
-
#initialize(parent_class: nil) { ... } ⇒ HeritableMethods
constructor
A new instance of HeritableMethods.
Constructor Details
#initialize(parent_class: nil) { ... } ⇒ HeritableMethods
Returns a new instance of HeritableMethods.
121 122 123 124 125 126 127 |
# File 'lib/sleeping_king_studios/tools/toolbox/heritable_data.rb', line 121 def initialize(parent_class: nil, &methods) super(&nil) @parent_class = parent_class class_exec(&methods) if methods end |
Instance Attribute Details
#parent_class ⇒ Class? (readonly)
Returns the parent data class.
130 131 132 |
# File 'lib/sleeping_king_studios/tools/toolbox/heritable_data.rb', line 130 def parent_class @parent_class end |
Instance Method Details
#each_heritable_module ⇒ Object
Iterates over the ::HeritableMethods modules for parent classes.
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sleeping_king_studios/tools/toolbox/heritable_data.rb', line 133 def each_heritable_module return enum_for(:each_heritable_module) unless block_given? ancestor = self while ancestor yield ancestor ancestor = ancestor.parent_class&.then { |mod| mod::HeritableMethods } end end |