Sha256: 911c0919623e1d9d7d0b5e46063eaca87a661b47f20cd893dabeb5c93c2d5e97

Contents?: true

Size: 657 Bytes

Versions: 3

Compression:

Stored size: 657 Bytes

Contents

class RMXStrongToWeakHash < Hash

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

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

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

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

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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rmx-0.6.2 lib/motion/RMXStrongToWeakHash.rb
rmx-0.6.1 lib/motion/RMXStrongToWeakHash.rb
rmx-0.6.0 lib/motion/RMXStrongToWeakHash.rb