Method: Weak::Map::StrongSecondaryKeys#each_key

Defined in:
lib/weak/map/strong_secondary_keys.rb

#each_key {|key| ... } ⇒ self, Enumerator

Calls the given block once for each live key in self, passing the key as a parameter. Returns the weak map itself.

If no block is given, an Enumerator is returned instead.

Yields:

  • (key)

    calls the given block once for each key in self

Yield Parameters:

  • key (Object)

    the key of the current key-value pair

Returns:

  • (self, Enumerator)

    self if a block was given or an Enumerator if no block was given.



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/weak/map/strong_secondary_keys.rb', line 101

def each_key
  return enum_for(__method__) { size } unless block_given?

  @keys.values.each do |raw_key|
    next if DeletedEntry === raw_key

    key = value!(raw_key)
    next unless (id = @key_map[key.__id__])
    if missing?(@values[id])
      @keys[id] = DeletedEntry.new
    else
      yield key
    end
  end

  self
end