Module: Contracts::Constraints
- Defined in:
- lib/contracts.rb,
lib/contracts/structured.rb
Defined Under Namespace
Classes: All, Anything, ArrayOf, Base, DuckType, HashOf, Length, Nilable, Nothing, OneOf, Predicate, Range, Regex, RespondTo, Shape, Tuple, Type, Union
Class Method Summary collapse
- .coerce(value) ⇒ Object
-
.shape(required: {}, optional: {}, allow_extra: false) ⇒ Object
Creates a required/optional Hash shape constraint.
-
.tuple(*items) ⇒ Object
Creates a fixed-length heterogeneous Array constraint.
Class Method Details
.coerce(value) ⇒ Object
340 |
# File 'lib/contracts.rb', line 340 def coerce(value) = value.respond_to?(:matches?) && value.respond_to?(:description) ? value : Type.new(value) |