Sha256: 74e24745ee6367c3e7b9c7d233ea96a3ac0836b2d85b33c61acca807de8514ac

Contents?: true

Size: 907 Bytes

Versions: 4

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module Kind
  module Of
    def self.call(klass, object, name: nil)
      return object if object.is_a?(klass)

      raise Kind::Error.new((name || klass.name), object)
    end

    def self.Class(object = Undefined)
      return Class if object == Undefined

      self.call(::Class, object)
    end

    const_set(:Class, ::Module.new do
      extend Checker

      def self.__kind; ::Class; end

      def self.class?(value); Kind::Is.Class(value); end

      def self.instance?(value); class?(value); end
    end)

    def self.Module(object = Undefined)
      return Module if object == Undefined

      self.call(::Module, object)
    end

    const_set(:Module, ::Module.new do
      extend Checker

      def self.__kind; ::Module; end

      def self.class?(value); Kind::Is.Module(value); end

      def self.instance?(value); class?(value); end
    end)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kind-1.5.0 lib/kind/of.rb
kind-1.4.0 lib/kind/of.rb
kind-1.3.0 lib/kind/of.rb
kind-1.2.0 lib/kind/of.rb