Class: Thy::Types::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/thy/types/variant.rb

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ Variant

Returns a new instance of Variant.



6
7
8
# File 'lib/thy/types/variant.rb', line 6

def initialize(types)
  @types = types
end

Instance Method Details

#check(value) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/thy/types/variant.rb', line 10

def check(value)
  if @types.any? { |t| t.check(value).success? }
    Result::Success
  else
    Result::Failure.new("Expected #{value.inspect} to be within types: #{@types.inspect}")
  end
end