Module: T::Props::WeakConstructor
Overview
typed: false
Constant Summary
Constants included from Helpers
Instance Method Summary collapse
Methods included from Helpers
#abstract!, #final!, #interface!, #mixes_in_class_methods
Instance Method Details
#initialize(hash = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/types/props/weak_constructor.rb', line 7 def initialize(hash={}) expected_keys = {} hash.each_key {|key| expected_keys[key] = true} decorator = self.class.decorator decorator.props.each do |p, rules| if hash.key?(p) expected_keys.delete(p) val = hash[p] elsif decorator.has_default?(rules) val = decorator.get_default(rules, self.class) else next end decorator.prop_set(self, p, val, rules) end unless expected_keys.empty? raise ArgumentError.new("#{@class}: Unrecognized properties in #with_props: #{expected_keys.keys.join(', ')}") end end |