class Ytry::Failure
Attributes
error[R]
Public Class Methods
new(value)
click to toggle source
# File lib/ytry.rb, line 126 def initialize value @error = value.freeze end
Public Instance Methods
==(other)
click to toggle source
# File lib/ytry.rb, line 133 def == other other.is_a?(Failure) && self.error == other.error end
===(other)
click to toggle source
# File lib/ytry.rb, line 136 def === other other.is_a?(Failure) && self.error === other.error end
empty?()
click to toggle source
# File lib/ytry.rb, line 130 def empty?() true end
get()
click to toggle source
# File lib/ytry.rb, line 129 def get() raise @error end
on_failure() { |error| ... }
click to toggle source
# File lib/ytry.rb, line 139 def on_failure return enum_for(__method__) unless block_given? Try { yield @error } return self end
recover(&block)
click to toggle source
# File lib/ytry.rb, line 144 def recover &block raise ArgumentError, 'missing block' unless block_given? candidate = Success.new(@error).map &block (!candidate.empty? && candidate.get.nil?) ? self : candidate end
recover_with(&block)
click to toggle source
# File lib/ytry.rb, line 149 def recover_with &block candidate = self.recover(&block) if (!candidate.empty? && !candidate.get.is_a?(Try)) raise(Try.invalid_argument('Block should evaluate to an instance of Try', candidate.get)) else candidate.flatten end end
to_ary()
click to toggle source
# File lib/ytry.rb, line 132 def to_ary() [] end
to_s()
click to toggle source
# File lib/ytry.rb, line 131 def to_s() "Failure(#{@error.inspect})" end