Module: Dry::Tuple::TypeCoercer

Defined in:
lib/dry/tuple/type_coercer.rb

Class Method Summary collapse

Class Method Details

.[](*input, **opts) ⇒ Object

Examples:

Usage

Dry::Tuple::TypeCoercer[Dry::Types['any'], Dry::Types['string']]

See Also:

  • Tuple.coerce


31
32
33
# File 'lib/dry/tuple/type_coercer.rb', line 31

def [](*input, **opts)
  call(input, **opts)
end

.TypeCoercer.call(array) ⇒ Object .TypeCoercer.call(input) ⇒ Object .TypeCoercer.call(type) ⇒ Object

Examples:

Usage

Dry::Tuple::TypeCoercer.([Dry::Types['any'], Dry::Types['string']])

Overloads:

  • .TypeCoercer.call(array) ⇒ Object

    Parameters:

    • array (Array<Mixed>)
  • .TypeCoercer.call(input) ⇒ Object

    Parameters:

  • .TypeCoercer.call(type) ⇒ Object

    Parameters:

    • type (Dry::Types::Constrained)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dry/tuple/type_coercer.rb', line 16

def call(input, returns: Undefined)
  case input when Array
    Dry::Types::Tuple.coerce(input)
  when Dry::Types::Tuple
    Undefined.default(returns, input)
  when Dry::Types::Constrained
    call(input.type, returns: input)
  when NilClass
    Dry::Types['nominal.tuple']
  end
end