Class: Arf::Types::MapType
- Defined in:
- lib/arf/types/map_type.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #coerce(val) ⇒ Object
-
#initialize(k, v) ⇒ MapType
constructor
A new instance of MapType.
- #resolved_types ⇒ Object
Methods inherited from BaseType
#bind, #coerce_value, #resolve_type
Constructor Details
#initialize(k, v) ⇒ MapType
Returns a new instance of MapType.
8 9 10 11 12 |
# File 'lib/arf/types/map_type.rb', line 8 def initialize(k, v) super() @key = k @value = v end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
6 7 8 |
# File 'lib/arf/types/map_type.rb', line 6 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/arf/types/map_type.rb', line 6 def value @value end |
Class Method Details
.[](k, v) ⇒ Object
14 |
# File 'lib/arf/types/map_type.rb', line 14 def self.[](k, v) = new(k, v) |
Instance Method Details
#coerce(val) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/arf/types/map_type.rb', line 24 def coerce(val) key_type, value_type = resolved_types val .transform_keys { coerce_value(_1, key_type) } .transform_values { coerce_value(_1, value_type) } end |
#resolved_types ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/arf/types/map_type.rb', line 16 def resolved_types return @resolved_types if @resolved_types key = resolve_type(@key) value = resolve_type(@value) @resolved_types = [key, value] end |