select()
public
Returns a new array consisting of
[key,value] pairs for which the block returns true. Also see
Hash.values_at.
h = { "a" => 100, "b" => 200, "c" => 300 }
h.select {|k,v| k > "a"}
h.select {|k,v| v < 200}
Show source
/*
* call-seq:
* hsh.select {|key, value| block} => array
*
* Returns a new array consisting of <code>[key,value]</code>
* pairs for which the block returns true.
* Also see <code>Hash.values_at</code>.
*
* h = { "a" => 100, "b" => 200, "c" => 300 }
* h.select {|k,v| k > "a"} #=> [["b", 200], ["c", 300]]
* h.select {|k,v| v < 200} #=> [["a", 100]]
*/
VALUE
rb_hash_select(hash)
VALUE hash;
{
VALUE result;
RETURN_ENUMERATOR(hash, 0, 0);
result = rb_ary_new();
rb_hash_foreach(hash, select_i, result);
return result;
}