select()
public
Returns a new hash consisting of entries for which the block
returns true.
If no block is given, an enumerator is returned instead.
h = { "a" => 100, "b" => 200, "c" => 300 }
h.select {|k,v| k > "a"}
h.select {|k,v| v < 200}
Show source
VALUE
rb_hash_select(VALUE hash)
{
VALUE result;
RETURN_ENUMERATOR(hash, 0, 0);
result = rb_hash_new();
rb_hash_foreach(hash, select_i, result);
return result;
}