class Anthropic::Internal::Type::ArrayOf
Array of items of a given type.
@generic Elem
@abstract
@api private
def self.[](type_info, spec = {}) = new(type_info, spec)
(**spec)-
:"nil?"(Boolean) -- -
:union(Proc) -- -
:enum(Proc) -- -
:const(NilClass, TrueClass, FalseClass, Integer, Float, Symbol) --
Parameters:
-
spec(Hash{Symbol=>Object}) -- . -
type_info(Hash{Symbol=>Object}, Proc, Anthropic::Internal::Type::Converter, Class) --
def self.[](type_info, spec = {}) = new(type_info, spec)
def ==(other)
-
(Boolean)-
Parameters:
-
other(Object) --
def ==(other) # rubocop:disable Layout/LineLength other.is_a?(Anthropic::Internal::Type::ArrayOf) && other.nilable? == nilable? && other.item_type == item_type # rubocop:enable Layout/LineLength end
def ===(other) = other.is_a?(Array) && other.all?(item_type)
-
(Boolean)-
Parameters:
-
other(Object) --
def ===(other) = other.is_a?(Array) && other.all?(item_type)
def coerce(value, state:)
-
(Array-
Options Hash:
(**state)-
:branched(Integer) -- -
:exactness(Hash{Symbol=>Object}) -- -
:strictness(Boolean, :strong) --
Parameters:
-
state(Hash{Symbol=>Object}) -- . -
value(Array) --
Other tags:
- Api: - private
def coerce(value, state:) exactness = state.fetch(:exactness) unless value.is_a?(Array) exactness[:no] += 1 return value end target = item_type exactness[:yes] += 1 value .map do |item| case [nilable?, item] in [true, nil] exactness[:yes] += 1 nil else Anthropic::Internal::Type::Converter.coerce(target, item, state: state) end end end
def dump(value, state:)
-
(Array-
Options Hash:
(**state)-
:can_retry(Boolean) --
Parameters:
-
state(Hash{Symbol=>Object}) -- . -
value(Array) --
Other tags:
- Api: - private
def dump(value, state:) target = item_type if value.is_a?(Array) value.map do Anthropic::Internal::Type::Converter.dump(target, _1, state: state) end else super end end
def initialize(type_info, spec = {})
(**spec)-
:"nil?"(Boolean) -- -
:union(Proc) -- -
:enum(Proc) -- -
:const(NilClass, TrueClass, FalseClass, Integer, Float, Symbol) --
Parameters:
-
spec(Hash{Symbol=>Object}) -- . -
type_info(Hash{Symbol=>Object}, Proc, Anthropic::Internal::Type::Converter, Class) --
Other tags:
- Api: - private
def initialize(type_info, spec = {}) @item_type_fn = Anthropic::Internal::Type::Converter.type_info(type_info || spec) @nilable = spec[:nil?] end
def item_type = @item_type_fn.call
-
(generic-)
Other tags:
- Api: - private
def item_type = @item_type_fn.call
def nilable? = @nilable
-
(Boolean)-
Other tags:
- Api: - private
def nilable? = @nilable