Class: Fear::Failure
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Instance Method Summary collapse
-
#===(other) ⇒ Boolean
Used in case statement.
- #failure? ⇒ true
-
#flatten ⇒ Failure
Self.
- #get ⇒ Object
-
#initialize(exception) ⇒ Failure
constructor
A new instance of Failure.
-
#or_else(*args) ⇒ Try
Of calling block.
- #recover {|| ... } ⇒ Try
- #recover_with {|| ... } ⇒ Try
-
#select ⇒ Failure
Self.
- #success? ⇒ Boolean
- #to_either ⇒ Left
Methods included from Try
#any?, #each, #flat_map, #get_or_else, #include?, #map, #match, matcher, #to_option
Constructor Details
#initialize(exception) ⇒ Failure
Returns a new instance of Failure.
9 10 11 |
# File 'lib/fear/failure.rb', line 9 def initialize(exception) @exception = exception end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
13 14 15 |
# File 'lib/fear/failure.rb', line 13 def exception @exception end |
Instance Method Details
#===(other) ⇒ Boolean
Used in case statement
75 76 77 78 79 80 81 |
# File 'lib/fear/failure.rb', line 75 def ===(other) if other.is_a?(Failure) exception === other.exception else super end end |
#failure? ⇒ true
21 22 23 |
# File 'lib/fear/failure.rb', line 21 def failure? true end |
#flatten ⇒ Failure
Returns self.
38 39 40 |
# File 'lib/fear/failure.rb', line 38 def flatten self end |
#get ⇒ Object
26 27 28 |
# File 'lib/fear/failure.rb', line 26 def get raise exception end |
#or_else(*args) ⇒ Try
Returns of calling block.
31 32 33 34 35 |
# File 'lib/fear/failure.rb', line 31 def or_else(*args) super rescue StandardError => error Failure.new(error) end |
#recover {|| ... } ⇒ Try
61 62 63 64 65 |
# File 'lib/fear/failure.rb', line 61 def recover Success.new(yield(exception)) rescue StandardError => error Failure.new(error) end |
#recover_with {|| ... } ⇒ Try
50 51 52 53 54 55 56 |
# File 'lib/fear/failure.rb', line 50 def recover_with yield(exception).tap do |result| Utils.assert_type!(result, Success, Failure) end rescue StandardError => error Failure.new(error) end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/fear/failure.rb', line 16 def success? false end |
#to_either ⇒ Left
68 69 70 |
# File 'lib/fear/failure.rb', line 68 def to_either Left.new(exception) end |