Method: Immutable::Hash#each

Defined in:
lib/immutable/hash.rb

#each {|key, value| ... } ⇒ self Also known as: each_pair

Call the block once for each key/value pair in this Hash, passing the key/value pair as parameters. No specific iteration order is guaranteed, though the order will be stable for any particular Hash.

Examples:

Immutable::Hash["A" => 1, "B" => 2, "C" => 3].each { |k, v| puts "k=#{k} v=#{v}" }

k=A v=1
k=C v=3
k=B v=2
# => Immutable::Hash["A" => 1, "B" => 2, "C" => 3]

Yields:

  • (key, value)

    Once for each key/value pair.

Returns:

  • (self)


346
347
348
349
350
# File 'lib/immutable/hash.rb', line 346

def each(&block)
  return to_enum if not block_given?
  @trie.each(&block)
  self
end