Class: Ytry::Failure

Inherits:
Object
  • Object
show all
Includes:
Try
Defined in:
lib/ytry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Try

ary_to_type, #each, #flat_map, #flatten, #get_or_else, #grep, #inspect, #or_else, #zip, #|

Constructor Details

#initialize(value) ⇒ Failure

Returns a new instance of Failure.



92
93
94
# File 'lib/ytry.rb', line 92

def initialize value
  @error = value.freeze
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



91
92
93
# File 'lib/ytry.rb', line 91

def error
  @error
end

Instance Method Details

#==(other) ⇒ Object



99
100
101
# File 'lib/ytry.rb', line 99

def == other
  other.is_a?(Failure) && self.error == other.error
end

#===(other) ⇒ Object



102
103
104
# File 'lib/ytry.rb', line 102

def === other
  other.is_a?(Failure) && self.error === other.error
end

#empty?Boolean

Returns:

  • (Boolean)


96
# File 'lib/ytry.rb', line 96

def empty?() true end

#getObject

Raises:



95
# File 'lib/ytry.rb', line 95

def get() raise @error end

#recover(&block) ⇒ Object

Raises:

  • (ArgumentError)


105
106
107
108
109
# File 'lib/ytry.rb', line 105

def recover &block
  raise ArgumentError, 'missing block' unless block_given?
  candidate = Success.new(@error).map &block
  (!candidate.empty? && candidate.get.nil?) ? self : candidate
end

#to_aryObject



98
# File 'lib/ytry.rb', line 98

def to_ary() [] end

#to_sObject



97
# File 'lib/ytry.rb', line 97

def to_s() "Failure(#{@error})" end