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, #to_a, #to_option
Constructor Details
#initialize(exception) ⇒ Failure
Returns a new instance of Failure.
8 9 10 |
# File 'lib/fear/failure.rb', line 8 def initialize(exception) @exception = exception end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
12 13 14 |
# File 'lib/fear/failure.rb', line 12 def exception @exception end |
Instance Method Details
#===(other) ⇒ Boolean
Used in case statement
74 75 76 77 78 79 80 |
# File 'lib/fear/failure.rb', line 74 def ===(other) if other.is_a?(Failure) exception === other.exception else super end end |
#failure? ⇒ true
20 21 22 |
# File 'lib/fear/failure.rb', line 20 def failure? true end |
#flatten ⇒ Failure
Returns self.
37 38 39 |
# File 'lib/fear/failure.rb', line 37 def flatten self end |
#get ⇒ Object
25 26 27 |
# File 'lib/fear/failure.rb', line 25 def get fail exception end |
#or_else(*args) ⇒ Try
Returns of calling block.
30 31 32 33 34 |
# File 'lib/fear/failure.rb', line 30 def or_else(*args) super rescue => error Failure.new(error) end |
#recover {|| ... } ⇒ Try
60 61 62 63 64 |
# File 'lib/fear/failure.rb', line 60 def recover Success.new(yield(exception)) rescue => error Failure.new(error) end |
#recover_with {|| ... } ⇒ Try
49 50 51 52 53 54 55 |
# File 'lib/fear/failure.rb', line 49 def recover_with yield(exception).tap do |result| Utils.assert_type!(result, Success, Failure) end rescue => error Failure.new(error) end |
#success? ⇒ Boolean
15 16 17 |
# File 'lib/fear/failure.rb', line 15 def success? false end |
#to_either ⇒ Left
67 68 69 |
# File 'lib/fear/failure.rb', line 67 def to_either Left.new(exception) end |