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, #|
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
#error ⇒ Object
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
96
|
# File 'lib/ytry.rb', line 96
def empty?() true end
|
#get ⇒ Object
95
|
# File 'lib/ytry.rb', line 95
def get() raise @error end
|
#recover(&block) ⇒ Object
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_ary ⇒ Object
98
|
# File 'lib/ytry.rb', line 98
def to_ary() [] end
|
#to_s ⇒ Object
97
|
# File 'lib/ytry.rb', line 97
def to_s() "Failure(#{@error})" end
|