module NRSER::Props::Immutable::Vector
Mixin for classes that extend {Hamster::Vector} and will use itself as the property value storage, requiring that property keys be non-negative integers.
Constants
- STORAGE
Constants
¶ ↑
Public Class Methods
included(base)
click to toggle source
Module
Methods
¶ ↑
# 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.metadata.storage STORAGE base.metadata.freeze base.extend ClassMethods end
new(values = {})
click to toggle source
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}.
Calls superclass method
# File lib/nrser/props/immutable/vector.rb, line 92 def initialize values = {} super_values = [] self.class.metadata.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