Sha256: ae72f0f26e1cf1d8d12d46448192e79a4665d0e7381d2b61a6373931d94d39df

Contents?: true

Size: 629 Bytes

Versions: 68

Compression:

Stored size: 629 Bytes

Contents

# frozen_string_literal: true
# typed: true

module T::Types
  # Validates that an object belongs to the specified class.
  class ClassOf < Base
    attr_reader :type

    def initialize(type)
      @type = type
    end

    # overrides Base
    def name
      "T.class_of(#{@type})"
    end

    # overrides Base
    def valid?(obj)
      obj.is_a?(Module) && obj <= @type
    end

    # overrides Base
    def subtype_of_single?(other)
      case other
      when ClassOf
        @type <= other.type
      else
        false
      end
    end

    # overrides Base
    def describe_obj(obj)
      obj.inspect
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
sorbet-runtime-0.5.9445 lib/types/types/class_of.rb
sorbet-runtime-0.5.9442 lib/types/types/class_of.rb
sorbet-runtime-0.5.9431 lib/types/types/class_of.rb
sorbet-runtime-0.5.9426 lib/types/types/class_of.rb
sorbet-runtime-0.5.9419 lib/types/types/class_of.rb
sorbet-runtime-0.5.9408 lib/types/types/class_of.rb
sorbet-runtime-0.5.9396 lib/types/types/class_of.rb
sorbet-runtime-0.5.9368 lib/types/types/class_of.rb
sorbet-runtime-0.5.9363 lib/types/types/class_of.rb
sorbet-runtime-0.5.9358 lib/types/types/class_of.rb
sorbet-runtime-0.5.9351 lib/types/types/class_of.rb
sorbet-runtime-0.5.9338 lib/types/types/class_of.rb
sorbet-runtime-0.5.9327 lib/types/types/class_of.rb
sorbet-runtime-0.5.9319 lib/types/types/class_of.rb
sorbet-runtime-0.5.9318 lib/types/types/class_of.rb
sorbet-runtime-0.5.9309 lib/types/types/class_of.rb
sorbet-runtime-0.5.9307 lib/types/types/class_of.rb
sorbet-runtime-0.5.9306 lib/types/types/class_of.rb
sorbet-runtime-0.5.9303 lib/types/types/class_of.rb
sorbet-runtime-0.5.9301 lib/types/types/class_of.rb