Class: Code::Type::Hash
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Hash
constructor
A new instance of Hash.
- #max_arguments ⇒ Object
- #min_arguments ⇒ Object
- #name ⇒ Object
- #valid?(argument) ⇒ Boolean
Constructor Details
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
6 7 8 |
# File 'lib/code/type/hash.rb', line 6 def hash @hash end |
Instance Method Details
#max_arguments ⇒ Object
32 33 34 |
# File 'lib/code/type/hash.rb', line 32 def max_arguments hash.sum { |_, value| max_arguments_of(value) } end |
#min_arguments ⇒ Object
28 29 30 |
# File 'lib/code/type/hash.rb', line 28 def min_arguments hash.sum { |_, value| min_arguments_of(value) } end |
#name ⇒ Object
36 37 38 |
# File 'lib/code/type/hash.rb', line 36 def name "{#{hash.map { |key, value| "#{key.inspect} => #{value.name}" }.join(", ")}}" end |
#valid?(argument) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/code/type/hash.rb', line 12 def valid?(argument) return false unless argument.is_a?(Object::Dictionary) argument = argument.raw (argument.keys + hash.keys).uniq.all? do |key| if hash[key] valid_for?( expected: hash[key], actual: argument[key] || Object::Nothing.new ) else false end end end |