Class: Mona::Result::OK
- Inherits:
-
Object
- Object
- Mona::Result::OK
- Defined in:
- lib/mona/result/ok.rb
Overview
A Successful (OK) result
Direct Known Subclasses
Instance Attribute Summary collapse
- #value ⇒ Object readonly
Instance Method Summary collapse
- #and_tap ⇒ Object
- #and_then ⇒ Object
- #deconstruct ⇒ Object
- #deconstruct_keys(_keys = nil) ⇒ Object
- #either(ok, _err) ⇒ Object
- #err ⇒ Object
- #err? ⇒ Boolean
-
#initialize(value) ⇒ OK
constructor
A new instance of OK.
- #ok {|@value| ... } ⇒ Object
- #ok? ⇒ Boolean
- #or_else ⇒ Object
- #to_result ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #value_or ⇒ Object
Constructor Details
#initialize(value) ⇒ OK
Returns a new instance of OK.
7 8 9 |
# File 'lib/mona/result/ok.rb', line 7 def initialize(value) @value = value.freeze end |
Instance Attribute Details
#value ⇒ Object (readonly)
11 12 13 |
# File 'lib/mona/result/ok.rb', line 11 def value @value end |
Instance Method Details
#and_tap ⇒ Object
27 |
# File 'lib/mona/result/ok.rb', line 27 def and_tap(&) = tap { yield @value } |
#and_then ⇒ Object
25 |
# File 'lib/mona/result/ok.rb', line 25 def and_then(&) = Result[yield @value] |
#deconstruct ⇒ Object
31 |
# File 'lib/mona/result/ok.rb', line 31 def deconstruct = [:ok, @value] |
#deconstruct_keys(_keys = nil) ⇒ Object
33 |
# File 'lib/mona/result/ok.rb', line 33 def deconstruct_keys(_keys = nil) = { ok: @value } |
#either(ok, _err) ⇒ Object
23 |
# File 'lib/mona/result/ok.rb', line 23 def either(ok, _err) = ok.call(@value) |
#err ⇒ Object
21 |
# File 'lib/mona/result/ok.rb', line 21 def err(&) = nil |
#err? ⇒ Boolean
17 |
# File 'lib/mona/result/ok.rb', line 17 def err? = false |
#ok {|@value| ... } ⇒ Object
19 |
# File 'lib/mona/result/ok.rb', line 19 def ok(&) = yield @value |
#ok? ⇒ Boolean
15 |
# File 'lib/mona/result/ok.rb', line 15 def ok? = true |
#or_else ⇒ Object
29 |
# File 'lib/mona/result/ok.rb', line 29 def or_else(&) = self |
#to_result ⇒ Object
35 |
# File 'lib/mona/result/ok.rb', line 35 def to_result = self |
#to_s ⇒ Object Also known as: inspect
37 |
# File 'lib/mona/result/ok.rb', line 37 def to_s = "#<OK #{@value.inspect}>" |
#value_or ⇒ Object
13 |
# File 'lib/mona/result/ok.rb', line 13 def value_or(&) = @value |