Class: Contracts::Builtin::Or
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Or
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb
Overview
Takes a variable number of contracts. The contract passes if any of the contracts pass. Example: Or[Fixnum, Float]
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(*vals) ⇒ Or
constructor
A new instance of Or.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(*vals) ⇒ Or
Returns a new instance of Or.
98 99 100 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 98 def initialize(*vals) @vals = vals end |
Instance Method Details
#to_s ⇒ Object
109 110 111 112 113 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 109 def to_s @vals[0, @vals.size-1].map do |x| InspectWrapper.create(x) end.join(", ") + " or " + InspectWrapper.create(@vals[-1]).to_s end |