Class: Dry::Data::Optional
- Inherits:
-
Object
- Object
- Dry::Data::Optional
- Defined in:
- lib/dry/data/optional.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #call(input) ⇒ Object (also: #[])
-
#initialize(type) ⇒ Optional
constructor
A new instance of Optional.
- #valid?(input) ⇒ Boolean
Constructor Details
#initialize(type) ⇒ Optional
Returns a new instance of Optional.
6 7 8 |
# File 'lib/dry/data/optional.rb', line 6 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/dry/data/optional.rb', line 4 def type @type end |
Instance Method Details
#call(input) ⇒ Object Also known as: []
14 15 16 |
# File 'lib/dry/data/optional.rb', line 14 def call(input) Maybe(type[input]) end |
#valid?(input) ⇒ Boolean
10 11 12 |
# File 'lib/dry/data/optional.rb', line 10 def valid?(input) type.valid?(input) end |