Class: Types::Array
Overview
Represents an array type with a specific item type.
“‘ruby type = Types::Array.new(Types::Integer) type.parse([“1”, “2”]) # => [1, 2] “`
Instance Method Summary collapse
- #composite? ⇒ Boolean
-
#initialize(item_type) ⇒ Array
constructor
A new instance of Array.
-
#map(values) ⇒ Object
Maps the given values using the item type’s parse method.
-
#parse(input) ⇒ Object
Parses the input as an array with the specified item type.
-
#resolve ⇒ Object
Resolves to the actual Ruby Array class.
- #to_rbs ⇒ Object
- #to_s ⇒ Object
Methods included from Generic
Constructor Details
#initialize(item_type) ⇒ Array
Returns a new instance of Array.
20 21 22 |
# File 'lib/types/array.rb', line 20 def initialize(item_type) @item_type = item_type end |
Instance Method Details
#map(values) ⇒ Object
Maps the given values using the item type’s parse method.
32 33 34 |
# File 'lib/types/array.rb', line 32 def map(values) values.map{|value| @item_type.parse(value)} end |
#parse(input) ⇒ Object
Parses the input as an array with the specified item type.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/types/array.rb', line 40 def parse(input) case input when ::String return parse_values(parse_string(input)) when ::Array return parse_values(input) else raise ArgumentError, "Cannot coerce #{input.inspect} into Array!" end end |
#resolve ⇒ Object
Resolves to the actual Ruby Array class.
63 64 65 |
# File 'lib/types/array.rb', line 63 def resolve ::Array end |
#to_rbs ⇒ Object
57 58 59 |
# File 'lib/types/array.rb', line 57 def to_rbs "Array[#{@item_type.to_rbs}]" end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/types/array.rb', line 52 def to_s "Array(#{@item_type})" end |