Class: Contracts::Builtin::Maybe

Inherits:
Or show all
Defined in:
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

Methods inherited from Or

#to_s, #valid?

Methods inherited from CallableClass

[]

Constructor Details

#initialize(*vals) ⇒ Maybe

Returns a new instance of Maybe.



552
553
554
# File 'lib/contracts/builtin_contracts.rb', line 552

def initialize(*vals)
  super(*(vals + [nil]))
end

Instance Method Details

#include_proc?Boolean

Returns:

  • (Boolean)


556
557
558
# File 'lib/contracts/builtin_contracts.rb', line 556

def include_proc?
  @vals.include? Proc
end