Class: Dry::Types::Safe
- Inherits:
-
Object
- Object
- Dry::Types::Safe
- Defined in:
- lib/dry/types/safe.rb
Instance Attribute Summary
Attributes included from Decorator
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
- #try(input, &block) ⇒ Object
Methods included from Builder
#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|
Methods included from Decorator
#constructor, #initialize, #respond_to_missing?, #valid?, #with
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dry::Types::Decorator
Instance Method Details
#call(input) ⇒ Object Also known as: []
9 10 11 12 13 14 15 16 17 |
# File 'lib/dry/types/safe.rb', line 9 def call(input) if type.primitive?(input) || type.is_a?(Sum) || type.is_a?(Constructor) type[input] else input end rescue TypeError input end |
#try(input, &block) ⇒ Object
20 21 22 |
# File 'lib/dry/types/safe.rb', line 20 def try(input, &block) type.try(input, &block) end |