Class: Candid::Internal::Types::Array
- Inherits:
-
Object
- Object
- Candid::Internal::Types::Array
- Includes:
- Type
- Defined in:
- lib/candid/internal/types/array.rb
Overview
An array of a specific type
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.[](type) ⇒ Candid::Internal::Types::Array
Instantiates a new ‘Array` of a given type.
Instance Method Summary collapse
-
#coerce(value, strict: strict?) ) ⇒ ::Array
Coerces a value into this array.
-
#initialize(type) ⇒ Array
constructor
private
A new instance of Array.
Methods included from Type
Methods included from JSON::Serializable
Constructor Details
#initialize(type) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Array.
24 25 26 |
# File 'lib/candid/internal/types/array.rb', line 24 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/candid/internal/types/array.rb', line 10 def type @type end |
Class Method Details
.[](type) ⇒ Candid::Internal::Types::Array
Instantiates a new ‘Array` of a given type
18 19 20 |
# File 'lib/candid/internal/types/array.rb', line 18 def [](type) new(type) end |
Instance Method Details
#coerce(value, strict: strict?) ) ⇒ ::Array
Coerces a value into this array
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/candid/internal/types/array.rb', line 33 def coerce(value, strict: strict?) unless value.is_a?(::Array) raise Errors::TypeError, "cannot coerce `#{value.class}` to Array<#{type}>" if strict return value end value.map do |element| Utils.coerce(type, element, strict: strict) end end |