class Opted::Result::Ok
Value object that represents a successful result
Public Class Methods
@param value [Object] a non-nil value to wrap @raise [ArgumentError] if provided value is nil
# File lib/opted/result/ok.rb, line 7 def initialize(value) if value.nil? fail ArgumentError.new("can't wrap nil") else @value = value end end
Public Instance Methods
If other object is also {Ok} and wraps equivalent value @param other [Object] any object @return [Boolean]
# File lib/opted/result/ok.rb, line 18 def ==(other) other.is_a?(Ok) && unwrap! == other.unwrap! end
(see AbstractResult#and
) @see Err#and
# File lib/opted/result/ok.rb, line 67 def and(other) other end
(see AbstractResult#and_then
) @see Err#and_then
# File lib/opted/result/ok.rb, line 73 def and_then yield unwrap! end
(see AbstractResult#err?
) @see Err#err?
# File lib/opted/result/ok.rb, line 31 def err? false end
(see AbstractResult#map
) @see Err#map
# File lib/opted/result/ok.rb, line 49 def map Ok.new(yield unwrap!) end
(see AbstractResult#map_err
) @see Err#map_err
# File lib/opted/result/ok.rb, line 55 def map_err self end
(see AbstractResult#match
) @see Err#match
# File lib/opted/result/ok.rb, line 91 def match(&block) Match.match_value(unwrap!, &block) end
(see AbstractResult#ok?
) @see Err#ok?
# File lib/opted/result/ok.rb, line 25 def ok? true end
(see AbstractResult#or
) @see Err#or
# File lib/opted/result/ok.rb, line 79 def or(_other) self end
(see AbstractResult#or_else
) @see Err#or_else
# File lib/opted/result/ok.rb, line 85 def or_else self end
(see AbstractResult#unwrap!
) @see Err#unwrap!
# File lib/opted/result/ok.rb, line 37 def unwrap! @value end
(see AbstractResult#unwrap_err!
) @see Err#unwrap_err!
# File lib/opted/result/ok.rb, line 43 def unwrap_err! fail UnwrapError.new(__method__, inspect) end
(see AbstractResult#unwrap_or
) @see Err#unwrap_or
# File lib/opted/result/ok.rb, line 61 def unwrap_or(_other_value) unwrap! end