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.9300 lib/types/types/class_of.rb
sorbet-runtime-0.5.9297 lib/types/types/class_of.rb
sorbet-runtime-0.5.9293 lib/types/types/class_of.rb
sorbet-runtime-0.5.9292 lib/types/types/class_of.rb
sorbet-runtime-0.5.9291 lib/types/types/class_of.rb
sorbet-runtime-0.5.9287 lib/types/types/class_of.rb
sorbet-runtime-0.5.9279 lib/types/types/class_of.rb
sorbet-runtime-0.5.9271 lib/types/types/class_of.rb
sorbet-runtime-0.5.9267 lib/types/types/class_of.rb
sorbet-runtime-0.5.9266 lib/types/types/class_of.rb
sorbet-runtime-0.5.9265 lib/types/types/class_of.rb
sorbet-runtime-0.5.9262 lib/types/types/class_of.rb
sorbet-runtime-0.5.9258 lib/types/types/class_of.rb
sorbet-runtime-0.5.9248 lib/types/types/class_of.rb
sorbet-runtime-0.5.9242 lib/types/types/class_of.rb
sorbet-runtime-0.5.9238 lib/types/types/class_of.rb
sorbet-runtime-0.5.9230 lib/types/types/class_of.rb
sorbet-runtime-0.5.9226 lib/types/types/class_of.rb
sorbet-runtime-0.5.9222 lib/types/types/class_of.rb
sorbet-runtime-0.5.9219 lib/types/types/class_of.rb