Class: Thy::Types::Option
- Inherits:
-
Object
- Object
- Thy::Types::Option
- Defined in:
- lib/thy/types/option.rb
Instance Method Summary collapse
- #check(value) ⇒ Object
-
#initialize(type) ⇒ Option
constructor
A new instance of Option.
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 |