Class: ObjectSpace::WeakMap

Inherits:
Object show all
Includes:
Enumerable
Defined in:
opal/opal/corelib/object_space.rb

Instance Method Summary collapse

Methods included from Enumerable

#all?, #any?, #chunk, #chunk_while, #collect, #collect_concat, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_entry, #each_slice, #each_with_index, #each_with_object, #entries, #enumerator_size, #filter_map, #find_all, #find_index, #first, #grep, #grep_v, #group_by, #inject, #lazy, #max, #max_by, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reject, #reverse_each, #slice_after, #slice_before, #slice_when, #sort, #sort_by, #sum, #take, #take_while, #tally, #to_h, #uniq, #zip

Constructor Details

#initializeWeakMap

Returns a new instance of WeakMap.



68
69
70
71
# File 'opal/opal/corelib/object_space.rb', line 68

def initialize
  @weak_map = `new WeakMap()`
  @primitive_map = {}
end

Instance Method Details

#[](p1) ⇒ Object



73
74
75
76
77
78
# File 'opal/opal/corelib/object_space.rb', line 73

def [](p1)
  %x{
    if (typeof p1 !== "function" && typeof p1 !== "object") return #{@primitive_map[p1]};
    return #{@weak_map}.get(p1);
  }
end

#[]=(p1, p2) ⇒ Object



80
81
82
83
84
85
# File 'opal/opal/corelib/object_space.rb', line 80

def []=(p1, p2)
  %x{
    if (typeof p1 !== "function" && typeof p1 !== "object") return #{@primitive_map[p1] = p2};
    return #{@weak_map}.set(p1, p2);
  }
end

#include?(p1) ⇒ Boolean Also known as: member?, key?

Returns:



87
88
89
90
91
92
# File 'opal/opal/corelib/object_space.rb', line 87

def include?(p1)
  %x{
    if (typeof p1 !== "function" && typeof p1 !== "object") return #{@primitive_map.key? p1};
    return #{@weak_map}.has(p1);
  }
end