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
- #call(input) ⇒ Dry::Monads::Maybe (also: #[])
- #default(value) ⇒ Object
- #maybe? ⇒ true
- #try(input) ⇒ Result::Success
Methods included from Builder
#constrained, #constrained_type, #constructor, #enum, #maybe, #optional, #safe, #|
Methods included from Decorator
#constrained?, #constructor, #decorate?, #default?, #initialize, #method_missing, #respond_to_missing?, #valid?
Methods included from Options
#initialize, #meta, #pristine, #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) ⇒ Dry::Monads::Maybe Also known as: []
15 16 17 |
# File 'lib/dry/types/extensions/maybe.rb', line 15 def call(input) input.is_a?(Dry::Monads::Maybe) ? input : Maybe(type[input]) end |
#default(value) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/dry/types/extensions/maybe.rb', line 34 def default(value) if value.nil? raise ArgumentError, "nil cannot be used as a default of a maybe type" else super end end |
#maybe? ⇒ true
27 28 29 |
# File 'lib/dry/types/extensions/maybe.rb', line 27 def maybe? true end |
#try(input) ⇒ Result::Success
22 23 24 |
# File 'lib/dry/types/extensions/maybe.rb', line 22 def try(input) Result::Success.new(Maybe(type[input])) end |