Class: Dry::Types::Maybe

Inherits:
Object
  • Object
show all
Includes:
Monads::Maybe::Mixin, Builder, Decorator
Defined in:
lib/dry/types/maybe.rb

Instance Attribute Summary

Attributes included from Decorator

#options, #type

Instance Method Summary collapse

Methods included from Builder

#constrained, #constrained_type, #constructor, #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: []



11
12
13
# File 'lib/dry/types/maybe.rb', line 11

def call(input)
  input.is_a?(Dry::Monads::Maybe) ? input : Maybe(type[input])
end

#default(value) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/dry/types/maybe.rb', line 16

def default(value)
  if value.nil?
    raise ArgumentError, "nil cannot be used as a default of a maybe type"
  else
    super
  end
end