Module: NRSER::Props::Immutable::Vector
- Included in:
- I8::Struct::Vector, Meta::Source::Location
- Defined in:
- lib/nrser/props/immutable/vector.rb
Overview
Mixin for classes that extend Hamster::Vector and will use itself as the property value storage, requiring that property keys be non-negative integers.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
Class Method Summary collapse
-
.included(base) ⇒ Object
Module Methods ======================================================================.
Instance Method Summary collapse
-
#initialize(values = {}) ⇒ Object
Since including classes are using themselves as storage, we need to tap into the ‘#initialize` chain in order to load property values from sources and pass an Array up to the super-method to instantiate the Hamster::Vector.
Class Method Details
.included(base) ⇒ Object
Module Methods
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/nrser/props/immutable/vector.rb', line 40 def self.included base unless base < Hamster::Vector raise binding.erb <<~END This class is only for including in {Hamster::Vector} subclasses! END end base.include NRSER::Props base..storage STORAGE base..freeze base.extend ClassMethods end |
Instance Method Details
#initialize(values = {}) ⇒ Object
Since including classes are using themselves as storage, we need to tap into the ‘#initialize` chain in order to load property values from sources and pass an Array up to the super-method to instantiate the Hamster::Vector.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/nrser/props/immutable/vector.rb', line 92 def initialize values = {} super_values = [] self.class..each_primary_prop_value_from( values ) { |prop, value| super_values[prop.index] = value } super super_values # Check additional type invariants self.class.invariants.each do |type| type.check self end end |