Class: Dry::Data::Type::Optional

Inherits:
Dry::Data::Type show all
Defined in:
lib/dry/data/type/optional.rb

Instance Attribute Summary

Attributes inherited from Dry::Data::Type

#constructor, #primitive

Instance Method Summary collapse

Methods inherited from Dry::Data::Type

[], #initialize, #name, passthrough_constructor, strict_constructor

Constructor Details

This class inherits a constructor from Dry::Data::Type

Instance Method Details

#call(input) ⇒ Object



9
10
11
# File 'lib/dry/data/type/optional.rb', line 9

def call(input)
  Maybe(input)
end

#valid?(input) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dry/data/type/optional.rb', line 13

def valid?(input)
  input.nil? || super
end

#|(other) ⇒ Object



5
6
7
# File 'lib/dry/data/type/optional.rb', line 5

def |(other)
  Data.SumType(self.class.new(constructor, other.primitive), other)
end