Class: Contracts::Or
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::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[Fixnum, Float]
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(*vals) ⇒ Or
constructor
A new instance of Or.
- #test_data ⇒ Object
-
#testable? ⇒ Boolean
this can only be tested IF all the sub-contracts have a test_data method.
- #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/builtin_contracts.rb', line 98 def initialize(*vals) @vals = vals end |
Instance Method Details
#test_data ⇒ Object
120 121 122 123 124 |
# File 'lib/contracts/builtin_contracts.rb', line 120 def test_data @vals.map { |val| Testable.test_data(val) }.flatten end |
#testable? ⇒ Boolean
this can only be tested IF all the sub-contracts have a test_data method
114 115 116 117 118 |
# File 'lib/contracts/builtin_contracts.rb', line 114 def testable? @vals.all? do |val| Testable.testable?(val) end end |
#to_s ⇒ Object
109 110 111 |
# File 'lib/contracts/builtin_contracts.rb', line 109 def to_s @vals[0, @vals.size-1].join(", ") + " or " + @vals[-1].to_s end |