Skip to content
instance method

Hash#select

() { (K, V) -> ::boolish } -> ::Hash[K, V]
() -> ::Enumerator[[ K, V ], ::Hash[K, V]]
select {|key, value| ... } → new_hash
select → new_enumerator

With a block given, calls the block with each entry’s key and value; returns a new hash whose entries are those for which the block returns a truthy value:

Example
h = {foo: 0, bar: 1, baz: 2}
h.select {|key, value| value < 2 } # => {foo: 0, bar: 1}

With no block given, returns a new Enumerator.

Related: see Methods for Deleting.

See also #select! #replace #reject! #shift also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0