Class: Contracts::Builtin::CollectionOf
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::CollectionOf
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb
Overview
Takes a collection(responds to :each) type and a contract. The related argument must be of specified collection type. Checks the contract against every element of the collection. If it passes for all elements, the contract passes. Example: CollectionOf[Array, Num]
Defined Under Namespace
Classes: Factory
Instance Method Summary collapse
-
#initialize(collection_class, contract) ⇒ CollectionOf
constructor
A new instance of CollectionOf.
- #to_s ⇒ Object
- #valid?(vals) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(collection_class, contract) ⇒ CollectionOf
Returns a new instance of CollectionOf.
277 278 279 280 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 277 def initialize(collection_class, contract) @collection_class = collection_class @contract = contract end |
Instance Method Details
#to_s ⇒ Object
290 291 292 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 290 def to_s "a collection #{@collection_class} of #{@contract}" end |