Sha256: 4ade4d58bee8836c3200ec7134dd7efd56210da480a0053f7a5e1ae1c31107ad

Contents?: true

Size: 1.5 KB

Versions: 499

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true
# typed: true

module T::Types
  class TypedSet < TypedEnumerable
    attr_reader :type

    def underlying_class
      Hash
    end

    # overrides Base
    def name
      "T::Set[#{@type.name}]"
    end

    # overrides Base
    def recursively_valid?(obj)
      # Re-implements non_forcing_is_a?
      return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
      return false unless Object.const_defined?(:Set) # Set is not loaded yet
      obj.is_a?(Set) && super
    end

    # overrides Base
    def valid?(obj)
      # Re-implements non_forcing_is_a?
      return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
      return false unless Object.const_defined?(:Set) # Set is not loaded yet
      obj.is_a?(Set)
    end

    def new(*args)
      # Fine for this to blow up, because hopefully if they're trying to make a
      # Set, they don't mind putting (or already have put) a `require 'set'` in
      # their program directly.
      Set.new(*T.unsafe(args))
    end

    class Untyped < TypedSet
      def initialize
        super(T.untyped)
      end

      def valid?(obj)
        # Re-implements non_forcing_is_a?
        return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
        return false unless Object.const_defined?(:Set) # Set is not loaded yet
        obj.is_a?(Set)
      end
    end
  end
end

Version data entries

499 entries across 493 versions & 3 rubygems

Version Path
sorbet-runtime-0.5.11170 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11164 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11163 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11162 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11158 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11156 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11155 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11152 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11151 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11150 lib/types/types/typed_set.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/typed_set.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/typed_set.rb
sorbet-runtime-0.5.11148 lib/types/types/typed_set.rb
sorbet-runtime-0.5.11147 lib/types/types/typed_set.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/typed_set.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/typed_set.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11108/lib/types/types/typed_set.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/typed_set.rb
sorbet-runtime-0.5.11146 lib/types/types/typed_set.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/sorbet-runtime-0.5.11104/lib/types/types/typed_set.rb