Class: TypeCoerce::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/sorbet-coerce/converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Converter

Returns a new instance of Converter.



16
17
18
# File 'lib/sorbet-coerce/converter.rb', line 16

def initialize(type)
  @type = type
end

Instance Method Details

#from(args, raise_coercion_error: nil, coerce_empty_to_nil: false) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/sorbet-coerce/converter.rb', line 28

def from(args, raise_coercion_error: nil, coerce_empty_to_nil: false)
  if raise_coercion_error.nil?
    raise_coercion_error = TypeCoerce::Configuration.raise_coercion_error
  end

  T.let(_convert(args, @type, raise_coercion_error, coerce_empty_to_nil), @type)
end

#newObject



20
21
22
# File 'lib/sorbet-coerce/converter.rb', line 20

def new
  self
end

#to_sObject



24
25
26
# File 'lib/sorbet-coerce/converter.rb', line 24

def to_s
  "#{name}#[#{@type.to_s}]"
end