class Dry::Struct::Sum
A sum type of two or more structs As opposed to Dry::Types::Sum::Constrained this type tries no to coerce data first.
Public Instance Methods
===(value)
click to toggle source
@return [boolean]
# File lib/dry/struct/sum.rb, line 42 def ===(value) left === value || right === value end
call(input)
click to toggle source
Calls superclass method
# File lib/dry/struct/sum.rb, line 12 def call(input) left.try_struct(input) do right.try_struct(input) { super } end end
try(input)
click to toggle source
@param [Hash{Symbol => Object},Dry::Struct] input @yieldparam [Dry::Types::Result::Failure] failure @yieldreturn [Dry::Types::ResultResult] @return [Dry::Types::Result]
Calls superclass method
# File lib/dry/struct/sum.rb, line 22 def try(input) if input.is_a?(Struct) try_struct(input) { super } else super end end
|(type)
click to toggle source
Build a new sum type @param [Dry::Types::Type] type @return [Dry::Types::Sum]
Calls superclass method
# File lib/dry/struct/sum.rb, line 33 def |(type) if type.is_a?(Class) && type <= Struct || type.is_a?(Sum) Sum.new(self, type) else super end end
Protected Instance Methods
try_struct(input) { || ... }
click to toggle source
@private
# File lib/dry/struct/sum.rb, line 49 def try_struct(input) left.try_struct(input) do right.try_struct(input) { yield } end end