Class: Mona::Err
Overview
An Err (failure) result, with optional reason, and metadata
Direct Known Subclasses
Constant Summary
Constants included from Result
Instance Attribute Summary collapse
-
#failure ⇒ Object
readonly
Returns the value of attribute failure.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Class Method Summary collapse
Instance Method Summary collapse
- #either(_ok, err) ⇒ Object
-
#initialize(failure, reason, **meta) ⇒ Err
constructor
A new instance of Err.
- #inspect ⇒ Object (also: #to_s)
Methods included from Result
#==, #and_tap, #and_then, #deconstruct, #deconstruct_keys, #err, #err?, #ok, #ok?, #or_else, #value_or
Constructor Details
#initialize(failure, reason, **meta) ⇒ Err
Returns a new instance of Err.
10 11 12 13 14 15 16 |
# File 'lib/mona/err.rb', line 10 def initialize(failure, reason, **) raise ArgumentError, "meta can't contain :reason or err: key" if .key?(:reason) || .key?(:err) @failure = failure @reason = reason = end |
Instance Attribute Details
#failure ⇒ Object (readonly)
Returns the value of attribute failure.
19 20 21 |
# File 'lib/mona/err.rb', line 19 def failure @failure end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
19 20 21 |
# File 'lib/mona/err.rb', line 19 def end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
19 20 21 |
# File 'lib/mona/err.rb', line 19 def reason @reason end |
Class Method Details
.[](failure, reason = nil, **meta) ⇒ Object
8 |
# File 'lib/mona/err.rb', line 8 def self.[](failure, reason = nil, **) = new(failure, reason, **) |
Instance Method Details
#either(_ok, err) ⇒ Object
21 |
# File 'lib/mona/err.rb', line 21 def either(_ok, err) = err.call(@failure, @reason, **) |
#inspect ⇒ Object Also known as: to_s
23 |
# File 'lib/mona/err.rb', line 23 def inspect = "Err(#{[failure, *reason, *meta.map { "#{_1}: #{_2}" }].join(", ")})" |