Sha256: 2a52fd92fac14621855c8efb3bbcee9a804d9f8d376a540d236ef93f0c203958

Contents?: true

Size: 846 Bytes

Versions: 11

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

module Kind
  class Error < StandardError
    INVALID_DEFAULT_ARG = 'the default value must be defined as an argument or block'.freeze

    def self.wrong_number_of_args!(given:, expected:)
      raise ArgumentError, "wrong number of arguments (given #{given}, expected #{expected})"
    end

    def self.invalid_default_arg!
      raise ArgumentError, INVALID_DEFAULT_ARG
    end

    def initialize(arg, object = UNDEFINED, label: nil)
      if UNDEFINED == object
        # Will be used when the exception was raised with a message. e.g:
        # raise Kind::Error, "some message"
        super(arg)
      else
        label_text = label ? "#{label}: " : ''

        super("#{label_text}#{object.inspect} expected to be a kind of #{arg}")
      end
    end

    private_constant :INVALID_DEFAULT_ARG
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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