Method: Immutable::Hash#select

Defined in:
lib/immutable/hash.rb

#select {|key, value| ... } ⇒ Hash Also known as: find_all, keep_if

Return a new Hash with all the key/value pairs for which the block returns true.

Examples:

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

Yields:

  • (key, value)

    Once for each key/value pair.

Yield Returns:

  • Truthy if this pair should be present in the new Hash.

Returns:



438
439
440
441
# File 'lib/immutable/hash.rb', line 438

def select(&block)
  return enum_for(:select) unless block_given?
  derive_new_hash(@trie.select(&block))
end