class FastMultiJson::Result

Result object pattern is from johnnunemaker.com/resilience-in-ruby/ e.g. github.com/github/github-ds/blob/fbda5389711edfb4c10b6c6bad19311dfcb1bac1/lib/github/result.rb

Public Class Methods

new() { || ... } click to toggle source
# File lib/fast_multi_json.rb, line 14
def initialize
  @value = yield
  @error = nil
rescue LoadError => e
  @error = e
end

Public Instance Methods

ok?() click to toggle source
# File lib/fast_multi_json.rb, line 21
def ok?
  @error.nil?
end
rescue() { |error| ... } click to toggle source
# File lib/fast_multi_json.rb, line 33
def rescue
  return self if ok?
  Result.new { yield(@error) }
end
value!() click to toggle source
# File lib/fast_multi_json.rb, line 25
def value!
  if ok?
    @value
  else
    raise @error
  end
end