Module: T::Types::TypedArray::Private::Pool

Defined in:
lib/types/types/typed_array.rb

Constant Summary collapse

CACHE_FROZEN_OBJECTS =
begin
  ObjectSpace::WeakMap.new[1] = 1
  true # Ruby 2.7 and newer
                       rescue ArgumentError # Ruby 2.6 and older
                         false
end

Class Method Summary collapse

Class Method Details

.type_for_module(mod) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/types/types/typed_array.rb', line 40

def self.type_for_module(mod)
  cached = @cache[mod]
  return cached if cached

  type = TypedArray.new(mod)

  if CACHE_FROZEN_OBJECTS || (!mod.frozen? && !type.frozen?)
    @cache[mod] = type
  end
  type
end