Sha256: a02d48fbcf4de8e0aaeef1feca4ce6a9f0add3f42db86ca2442c9531fe3304b5

Contents?: true

Size: 988 Bytes

Versions: 11

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module Kind
  module Result::Abstract
    def failure?
      false
    end

    def failed?
      failure?
    end

    def success?
      false
    end

    def succeeded?
      success?
    end

    def on(&block)
      raise NotImplementedError
    end

    def on_success(types = Undefined, matcher = Undefined)
      raise NotImplementedError
    end

    def on_failure(types = Undefined, matcher = Undefined)
      raise NotImplementedError
    end

    def result?(types, matcher)
      undef_t = Undefined == (t = types)
      undef_m = Undefined == (m = matcher)

      return true if undef_t && undef_m

      if !undef_t && undef_m && !(Array === types || Symbol === types)
        m, t = types, matcher

        undef_m, undef_t = false, true
      end

      is_type = undef_t || (::Array === t ? t.empty? || t.include?(type) : t == type)
      is_type && (undef_m || m === value)
    end

    def to_ary
      [type, value]
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
kind-5.10.0 lib/kind/result/abstract.rb
kind-5.9.0 lib/kind/result/abstract.rb
kind-5.8.1 lib/kind/result/abstract.rb
kind-5.8.0 lib/kind/result/abstract.rb
kind-5.7.0 lib/kind/result/abstract.rb
kind-5.6.0 lib/kind/result/abstract.rb
kind-5.5.0 lib/kind/result/abstract.rb
kind-5.4.1 lib/kind/result/abstract.rb
kind-5.4.0 lib/kind/result/abstract.rb
kind-5.3.0 lib/kind/result/abstract.rb
kind-5.2.0 lib/kind/result/abstract.rb