class WeakStorage

Public Class Methods

new(key_class, val_class) click to toggle source
Calls superclass method WeakStore.new
# File core/lib/weakstorage.rb, line 176
def initialize(key_class, val_class)
  @key_class, @val_class = key_class, val_class
  super()
end

Public Instance Methods

[](key) click to toggle source
# File core/lib/weakstorage.rb, line 181
def [](key)
  begin
    result = atomic{
      ObjectSpace._id2ref(storage[key]) if storage.has_key?(key) }
    type_strict result => @val_class if result
    result
  rescue RangeError => e
    error "#{key} was deleted"
    nil end end
Also aliased as: add
[]=(key, val) click to toggle source
# File core/lib/weakstorage.rb, line 192
def []=(key, val)
  type_strict key => @key_class, val => @val_class
  atomic{
    ObjectSpace.define_finalizer(val, &gen_deleter)
    storage[key] = val.object_id } end
Also aliased as: store
add(key)
Alias for: []
has_key?(key) click to toggle source
# File core/lib/weakstorage.rb, line 199
def has_key?(key)
  atomic{
    storage.has_key?(key) } end
inspect() click to toggle source
# File core/lib/weakstorage.rb, line 203
def inspect
  atomic{ "#<WeakStorage(#{@key_class} => #{@val_class}): #{storage.size}>" }
end
store(key, val)
Alias for: []=