class Opted::Result::Ok

Value object that represents a successful result

Public Class Methods

new(value) click to toggle source

@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

==(other) click to toggle source

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
Also aliased as: eql?
and(other) click to toggle source

(see AbstractResult#and) @see Err#and

# File lib/opted/result/ok.rb, line 67
def and(other)
  other
end
and_then() { |unwrap!| ... } click to toggle source

(see AbstractResult#and_then) @see Err#and_then

# File lib/opted/result/ok.rb, line 73
def and_then
  yield unwrap!
end
eql?(other)
Alias for: ==
err?() click to toggle source

(see AbstractResult#err?) @see Err#err?

# File lib/opted/result/ok.rb, line 31
def err?
  false
end
map() { |unwrap!)| ... } click to toggle source

(see AbstractResult#map) @see Err#map

# File lib/opted/result/ok.rb, line 49
def map
  Ok.new(yield unwrap!)
end
map_err() click to toggle source

(see AbstractResult#map_err) @see Err#map_err

# File lib/opted/result/ok.rb, line 55
def map_err
  self
end
match(&block) click to toggle source

(see AbstractResult#match) @see Err#match

# File lib/opted/result/ok.rb, line 91
def match(&block)
  Match.match_value(unwrap!, &block)
end
ok?() click to toggle source

(see AbstractResult#ok?) @see Err#ok?

# File lib/opted/result/ok.rb, line 25
def ok?
  true
end
or(_other) click to toggle source

(see AbstractResult#or) @see Err#or

# File lib/opted/result/ok.rb, line 79
def or(_other)
  self
end
or_else() click to toggle source

(see AbstractResult#or_else) @see Err#or_else

# File lib/opted/result/ok.rb, line 85
def or_else
  self
end
unwrap!() click to toggle source

(see AbstractResult#unwrap!) @see Err#unwrap!

# File lib/opted/result/ok.rb, line 37
def unwrap!
  @value
end
unwrap_err!() click to toggle source

(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
unwrap_or(_other_value) click to toggle source

(see AbstractResult#unwrap_or) @see Err#unwrap_or

# File lib/opted/result/ok.rb, line 61
def unwrap_or(_other_value)
  unwrap!
end