Class: Thy::Types::Option

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

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Option

Returns a new instance of Option.



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

def initialize(type)
  @type = type
end

Instance Method Details

#check(value) ⇒ Object



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

def check(value)
  return Result::Success if value.nil?

  if @type.check(value).success?
    Result::Success
  else
    Result::Failure.new("Expected #{value.inspect} to be of type #{@type.inspect}")
  end
end