Sha256: 7127ab7006440e1916ff626938e0a07cc25a6bbd2badc4c2fd744a39d0b71b2d

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

require "resultt/version"
require "resultt/result_methods"

module Resultt
  class NilValueError < StandardError; end;

  def Result
    success = Success.new yield
    raise NilValueError, 'Resultt returned a nil value' if success.value.nil?

    success
  rescue StandardError => e
    Error.new(e)
  end

  def Success(value)
    Success.new(value)
  end

  def Error(error)
    Error.new(error)
  end

  class Success
    include ResultMethods

    attr_reader :value

    def initialize(value)
      @value = value
    end

    def ok?
      true
    end
    alias success? ok?

    def error?
      false
    end
  end

  class Error
    include ResultMethods

    attr_reader :error

    def initialize(error)
      @error = error
    end

    def error?
      true
    end

    def ok?
      false
    end
    alias success? ok?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
resultt-0.1.0 lib/resultt.rb