Class: Resonad::Success
Constant Summary
Constants inherited from Resonad
Mixin, NIL_FAILURE, NIL_SUCCESS, VERSION
Constants included from PublicMixin
PublicMixin::Failure, PublicMixin::Success
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #deconstruct ⇒ Object
- #deconstruct_keys(_) ⇒ Object
- #error ⇒ Object
-
#initialize(value) ⇒ Success
constructor
A new instance of Success.
- #success? ⇒ Boolean
Methods inherited from Resonad
#and_then, #bad?, #failed?, #failure?, #flat_map, #flat_map_error, #if_bad, #if_failed, #if_failure, #if_ok, #if_success, #if_successful, #map, #map_error, #map_value, #ok?, #on_bad, #on_failed, #on_failure, #on_ok, #on_success, #on_successful, #or_else, #otherwise, rescuing_from, #successful?, #when_bad, #when_failed, #when_failure, #when_ok, #when_success, #when_successful
Methods included from PublicMixin
#Failure, #Success, #failure, #success
Constructor Details
#initialize(value) ⇒ Success
Returns a new instance of Success.
16 17 18 19 |
# File 'lib/resonad.rb', line 16 def initialize(value) @value = value freeze end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/resonad.rb', line 6 def value @value end |
Class Method Details
.[](value = nil) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/resonad.rb', line 8 def self.[](value = nil) if nil == value NIL_SUCCESS else new(value) end end |
Instance Method Details
#deconstruct ⇒ Object
25 26 27 |
# File 'lib/resonad.rb', line 25 def deconstruct [:success, value] end |
#deconstruct_keys(_) ⇒ Object
29 30 31 |
# File 'lib/resonad.rb', line 29 def deconstruct_keys(_) { value: value } end |
#error ⇒ Object
33 34 35 |
# File 'lib/resonad.rb', line 33 def error raise NonExistentError, "Success resonads do not have errors" end |
#success? ⇒ Boolean
21 22 23 |
# File 'lib/resonad.rb', line 21 def success? true end |