Class: Contracts::Builtin::Or
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Or
- Defined in:
- lib/contracts/builtin_contracts.rb
Overview
Takes a variable number of contracts. The contract passes if any of the contracts pass. Example: Or[Integer, 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.
100 101 102 103 |
# File 'lib/contracts/builtin_contracts.rb', line 100 def initialize(*vals) super() @vals = vals end |
Instance Method Details
#to_s ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/contracts/builtin_contracts.rb', line 112 def to_s # rubocop:disable Style/StringConcatenation @vals[0, @vals.size-1].map do |x| InspectWrapper.create(x) end.join(", ") + " or " + InspectWrapper.create(@vals[-1]).to_s # rubocop:enable Style/StringConcatenation end |