Class: Contracts::Builtin::Maybe
- Inherits:
-
Or
- Object
- CallableClass
- Or
- Contracts::Builtin::Maybe
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb
Overview
Takes a Contract. The contract passes if the contract passes or the given value is nil. Maybe(foo) is equivalent to Or[foo, nil].
Instance Method Summary collapse
- #include_proc? ⇒ Boolean
-
#initialize(*vals) ⇒ Maybe
constructor
A new instance of Maybe.
Methods inherited from Or
Methods inherited from CallableClass
Constructor Details
#initialize(*vals) ⇒ Maybe
Returns a new instance of Maybe.
521 522 523 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 521 def initialize(*vals) super(*(vals + [nil])) end |
Instance Method Details
#include_proc? ⇒ Boolean
525 526 527 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 525 def include_proc? @vals.include? Proc end |