Class: RMXStrongToWeakHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/motion/RMXStrongToWeakHash.rb

Direct Known Subclasses

RMXSynchronizedStrongToWeakHash

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/motion/RMXStrongToWeakHash.rb', line 3

def [](key)
  if weak = super
    if val = weak.value
      val
    end
  end
end

#[]=(key, value) ⇒ Object



11
12
13
14
# File 'lib/motion/RMXStrongToWeakHash.rb', line 11

def []=(key, value)
  super(key, value.nil? ? nil : RMXWeakHolder.new(value))
  value
end

#delete(key) ⇒ Object



16
17
18
19
20
# File 'lib/motion/RMXStrongToWeakHash.rb', line 16

def delete(key)
  if val = super
    val.value
  end
end

#keysObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/motion/RMXStrongToWeakHash.rb', line 22

def keys
  out = []
  _keys = [] + super
  while _keys.size > 0
    key = _keys.shift
    if val = self[key]
      out << key
    end
  end
  out
end

#valuesObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/motion/RMXStrongToWeakHash.rb', line 34

def values
  out = []
  values = [] + super
  while values.size > 0
    value = values.shift
    if val = value.value
      out << val
    end
  end
  out
end