These are chat archives for dry-rb/chat
Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
How to understand this behaviour:
>> Dry::Types['float'] => 1 >> Dry::Types['float'].constrained(gteq: 1.0) Dry::Types::ConstraintError: 1 violates constraints (1 must be an instance of Float failed) from /Users/v.kolesnikov/.rvm/gems/ruby-2.5.0/gems/dry-types-0.13.2/lib/dry/types/constrained.rb:28:in `block in call'
Why the first type definition doesn't check the actual type of value? But the constrained does.
Dry::Types[‘float’] is just a definition which is not really usable for anything except type annotation.
When you use
.constrained, it creates a
Dry::Types::Constrained on top of the old type. IIRC, there are two kinds of constrained types: strict and coercible (available under
#constrainedon plain definitions, not sure