class Resultr::ResultProxy

Public Class Methods

new(result) click to toggle source
# File lib/resultr/result_proxy.rb, line 5
def initialize(result)
  @result = result
  @resolved = false
  @resolved_value = nil
end

Public Instance Methods

err() { |reason| ... } click to toggle source
# File lib/resultr/result_proxy.rb, line 21
def err
  resolve_result_if :err? do |reason|
    if block_given?
      yield reason
    else
      reason
    end
  end
end
ok() { |value| ... } click to toggle source
# File lib/resultr/result_proxy.rb, line 11
def ok
  resolve_result_if :ok? do |value|
    if block_given?
      yield value
    else
      value
    end
  end
end

Private Instance Methods

resolve_result_if(condition) { |value| ... } click to toggle source
# File lib/resultr/result_proxy.rb, line 33
def resolve_result_if(condition)
  if @resolved
    @resolved_value
  elsif @result.send(condition)
    @resolved = true
    @resolved_value = yield @result.value
  end
end