Class: Contracts::Builtin::And
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::And
- 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 all contracts pass. Example: And[Fixnum, Float]
Instance Method Summary collapse
-
#initialize(*vals) ⇒ And
constructor
A new instance of And.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(*vals) ⇒ And
Returns a new instance of And.
143 144 145 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 143 def initialize(*vals) @vals = vals end |
Instance Method Details
#to_s ⇒ Object
154 155 156 157 158 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 154 def to_s @vals[0, @vals.size-1].map do |x| InspectWrapper.create(x) end.join(", ") + " and " + InspectWrapper.create(@vals[-1]).to_s end |