Module: Weak::Map::AbstractStrongKeys Abstract

Included in:
StrongKeys, StrongSecondaryKeys
Defined in:
lib/weak/map/abstract_strong_keys.rb

Overview

This module is abstract.

This module implements a common subset of (helper-)methods for a Weak::Map with an ‘ObjectSpace::WeakMap` with strong keys, i.e., StrongKeys and StrongSecondaryKeys.

Instance Method Summary collapse

Instance Method Details

#keysArray

Note:

In contrast to a ‘Hash`, `Weak::Map`s do not necessarily retain insertion order.

Returns an ‘Array` containing all keys of the map for which we have a valid value. Keys with garbage-collected values are excluded.

Returns:

  • (Array)

    an ‘Array` containing all keys of the map for which we have a valid value. Keys with garbage-collected values are excluded.

See Also:

[View source]

20
21
22
# File 'lib/weak/map/abstract_strong_keys.rb', line 20

def keys
  each_key.to_a
end

#sizeInteger

Returns the number of live key-value pairs in ‘self`.

Returns:

  • (Integer)

    the number of live key-value pairs in ‘self`

[View source]

25
26
27
# File 'lib/weak/map/abstract_strong_keys.rb', line 25

def size
  each_key.count
end

#valuesArray

Note:

In contrast to a ‘Hash`, `Weak::Map`s do not necessarily retain insertion order.

Returns an ‘Array` containing all values of the map for which we have a valid key. Values with garbage-collected keys are excluded.

Returns:

  • (Array)

    an ‘Array` containing all values of the map for which we have a valid key. Values with garbage-collected keys are excluded.

See Also:

[View source]

30
31
32
# File 'lib/weak/map/abstract_strong_keys.rb', line 30

def values
  each_value.to_a
end