Sha256: 10820d5d3de05ab0111d773c6ac243a130a022ce493ca5dc41669d4ab9f9ce9f

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'kind/version'

require 'kind/__lib__/kind'
require 'kind/__lib__/undefined'

require 'kind/basic/undefined'
require 'kind/basic/error'

module Kind
  extend self

  def is?(kind, arg)
    KIND.is?(kind, arg)
  end

  def is(*args)
    warn '[DEPRECATION] Kind.is will behave like Kind.is! in the next major release; ' \
        'use Kind.is? instead.'

    is?(*args)
  end

  def is!(kind, arg, label: nil)
    return arg if KIND.is?(kind, arg)

    label_text = label ? "#{label}: " : ''

    raise Kind::Error.new("#{label_text}#{arg} expected to be a #{kind}")
  end

  def of?(kind, *args)
    KIND.of?(kind, args)
  end

  def of_class?(value)
    OF.class?(value)
  end

  def of_module?(value)
    OF.module?(value)
  end

  def respond_to?(value, *method_names)
    return super(value) if method_names.empty?

    KIND.interface?(method_names, value)
  end

  def of(kind, value, label: nil)
    STRICT.object_is_a(kind, value, label)
  end

  alias_method :of!, :of

  def of_class(value)
    STRICT.class!(value)
  end

  def of_module(value)
    STRICT.module!(value)
  end

  def of_module_or_class(value)
    STRICT.module_or_class(value)
  end

  def respond_to(value, *method_names)
    method_names.each { |method_name| KIND.respond_to!(method_name, value) }

    value
  end
  alias_method :respond_to!, :respond_to

  def value(kind, value, default:)
    KIND.value(kind, value, of(kind, default))
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kind-5.4.1 lib/kind/basic.rb
kind-5.4.0 lib/kind/basic.rb
kind-5.3.0 lib/kind/basic.rb