Class: TypedContracts::MaybeOf
- Inherits:
-
Contracts::CallableClass
- Object
- Contracts::CallableClass
- TypedContracts::MaybeOf
- Defined in:
- lib/typed_contracts.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#vals ⇒ Object
readonly
Returns the value of attribute vals.
Instance Method Summary collapse
-
#initialize(*vals) ⇒ MaybeOf
constructor
A new instance of MaybeOf.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Constructor Details
#initialize(*vals) ⇒ MaybeOf
Returns a new instance of MaybeOf.
13 14 15 |
# File 'lib/typed_contracts.rb', line 13 def initialize(*vals) @vals = vals end |
Instance Attribute Details
#vals ⇒ Object (readonly)
Returns the value of attribute vals.
12 13 14 |
# File 'lib/typed_contracts.rb', line 12 def vals @vals end |
Instance Method Details
#to_s ⇒ Object
17 18 19 |
# File 'lib/typed_contracts.rb', line 17 def to_s "MaybeOf[#{@vals.first}]" end |
#valid?(val) ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/typed_contracts.rb', line 21 def valid?(val) return false unless val.is_a?(Kleisli::Maybe) && @vals.size == 1 inner_valid, = Contract.valid?(val.value, @vals.first) inner_valid || val.value.nil? end |