An ObjectSpace::WeakMap object holds references to any objects, but those objects can get garbage collected.
This class is mostly used internally by WeakRef, please use lib/weakref.rb
for the public interface.
Methods
Instance Public methods
[](p1)
Link
Retrieves a weakly referenced object with the given key
Source: show
static VALUE wmap_aref(VALUE self, VALUE wmap) { st_data_t data; VALUE obj; struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); if (!st_lookup(w->wmap2obj, (st_data_t)wmap, &data)) return Qnil; obj = (VALUE)data; if (!is_id_value(objspace, obj)) return Qnil; if (!is_live_object(objspace, obj)) return Qnil; return obj; }
[]=(p1, p2)
Link
Creates a weak reference from the given key to the given value
Source: show
static VALUE wmap_aset(VALUE self, VALUE wmap, VALUE orig) { st_data_t data; VALUE rids; struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); rb_define_final(orig, w->final); rb_define_final(wmap, w->final); if (st_lookup(w->obj2wmap, (st_data_t)orig, &data)) { rids = (VALUE)data; } else { rids = rb_ary_tmp_new(1); st_insert(w->obj2wmap, (st_data_t)orig, (st_data_t)rids); } rb_ary_push(rids, wmap); st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig); return nonspecial_obj_id(orig); }