Class: Dry::Struct::Sum
- Inherits:
-
Types::Sum::Constrained
- Object
- Types::Sum::Constrained
- Dry::Struct::Sum
- Defined in:
- lib/dry/struct/sum.rb
Overview
A sum type of two or more structs As opposed to Dry::Types::Sum::Constrained this type tries no to coerce data first.
Instance Method Summary collapse
- #===(value) ⇒ boolean
- #call(input) ⇒ Object
- #try(input) {|failure| ... } ⇒ Dry::Types::Result
-
#|(type) ⇒ Dry::Types::Sum
Build a new sum type.
Instance Method Details
#===(value) ⇒ boolean
39 40 41 |
# File 'lib/dry/struct/sum.rb', line 39 def ===(value) left === value || right === value end |
#call(input) ⇒ Object
9 10 11 12 13 |
# File 'lib/dry/struct/sum.rb', line 9 def call(input) left.try_struct(input) do right.try_struct(input) { super } end end |
#try(input) {|failure| ... } ⇒ Dry::Types::Result
19 20 21 22 23 24 25 |
# File 'lib/dry/struct/sum.rb', line 19 def try(input) if input.is_a?(Struct) try_struct(input) { super } else super end end |