Class: Dry::Types::Maybe
- Inherits:
-
Object
- Object
- Dry::Types::Maybe
- Defined in:
- lib/dry/types/extensions/maybe.rb
Instance Attribute Summary
Attributes included from Decorator
Attributes included from Options
Instance Method Summary collapse
Methods included from Builder
#constrained, #constrained_type, #constructor, #enum, #maybe, #optional, #safe, #|
Methods included from Decorator
#constrained?, #constructor, #default?, #initialize, #respond_to_missing?, #valid?
Methods included from Options
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: []
12 13 14 |
# File 'lib/dry/types/extensions/maybe.rb', line 12 def call(input) input.is_a?(Dry::Monads::Maybe) ? input : Maybe(type[input]) end |
#default(value) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/dry/types/extensions/maybe.rb', line 25 def default(value) if value.nil? raise ArgumentError, "nil cannot be used as a default of a maybe type" else super end end |
#maybe? ⇒ Boolean
21 22 23 |
# File 'lib/dry/types/extensions/maybe.rb', line 21 def maybe? true end |