Class: Ytry::Failure
- Inherits:
-
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, zip, #|
Constructor Details
#initialize(value) ⇒ Failure
Returns a new instance of Failure.
95
96
97
|
# File 'lib/ytry.rb', line 95
def initialize value
@error = value.freeze
end
|
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
94
95
96
|
# File 'lib/ytry.rb', line 94
def error
@error
end
|
Instance Method Details
#==(other) ⇒ Object
102
103
104
|
# File 'lib/ytry.rb', line 102
def == other
other.is_a?(Failure) && self.error == other.error
end
|
#===(other) ⇒ Object
105
106
107
|
# File 'lib/ytry.rb', line 105
def === other
other.is_a?(Failure) && self.error === other.error
end
|
#empty? ⇒ Boolean
99
|
# File 'lib/ytry.rb', line 99
def empty?() true end
|
#get ⇒ Object
98
|
# File 'lib/ytry.rb', line 98
def get() raise @error end
|
#recover(&block) ⇒ Object
108
109
110
111
112
|
# File 'lib/ytry.rb', line 108
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_ary ⇒ Object
101
|
# File 'lib/ytry.rb', line 101
def to_ary() [] end
|
#to_s ⇒ Object
100
|
# File 'lib/ytry.rb', line 100
def to_s() "Failure(#{@error.inspect})" end
|