Module: NRSER::Props::Immutable::Hash::InstanceMethods
- Defined in:
- lib/nrser/props/immutable/hash.rb
Overview
module ClassMethods
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::Hash.
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::Hash.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/nrser/props/immutable/hash.rb', line 92 def initialize values = {} # Handles things like `[[:x, 1], [:y, 2]]` values = values.to_h unless values.respond_to?( :each_pair ) super_values = {} self.class.. each_primary_prop_value_from( values ) { |prop, value| super_values[prop.name] = value } super super_values # Check additional type invariants self.class.invariants.each do |type| type.check self end end |