Class: Typed::Builder::SumType

Inherits:
Object
  • Object
show all
Includes:
BaseType
Defined in:
lib/typed/builder.rb

Instance Method Summary collapse

Methods included from BaseType

#call, #constrained, #constructor, #default, #enum, #instance, #missable, #nullable, #|

Constructor Details

#initialize(type_a, type_b) ⇒ SumType

Returns a new instance of SumType.



186
187
188
189
# File 'lib/typed/builder.rb', line 186

def initialize(type_a, type_b)
    @type_a = type_a
    @type_b = type_b
end

Instance Method Details

#process(value) ⇒ Object



191
192
193
194
195
196
# File 'lib/typed/builder.rb', line 191

def process(value)
    result = type_a.process(value)
    return result if result.ok

    type_b.process(value)
end