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.9539 lib/types/types/class_of.rb
sorbet-runtime-0.5.9538 lib/types/types/class_of.rb
sorbet-runtime-0.5.9534 lib/types/types/class_of.rb
sorbet-runtime-0.5.9531 lib/types/types/class_of.rb
sorbet-runtime-0.5.9528 lib/types/types/class_of.rb
sorbet-runtime-0.5.9519 lib/types/types/class_of.rb
sorbet-runtime-0.5.9507 lib/types/types/class_of.rb
sorbet-runtime-0.5.9494 lib/types/types/class_of.rb
sorbet-runtime-0.5.9491 lib/types/types/class_of.rb
sorbet-runtime-0.5.9482 lib/types/types/class_of.rb
sorbet-runtime-0.5.9475 lib/types/types/class_of.rb
sorbet-runtime-0.5.9470 lib/types/types/class_of.rb
sorbet-runtime-0.5.9468 lib/types/types/class_of.rb
sorbet-runtime-0.5.9465 lib/types/types/class_of.rb
sorbet-runtime-0.5.9464 lib/types/types/class_of.rb
sorbet-runtime-0.5.9460 lib/types/types/class_of.rb
sorbet-runtime-0.5.9455 lib/types/types/class_of.rb
sorbet-runtime-0.5.9453 lib/types/types/class_of.rb
sorbet-runtime-0.5.9452 lib/types/types/class_of.rb
sorbet-runtime-0.5.9449 lib/types/types/class_of.rb