Method: Hash#values_at
- Defined in:
- hash.c
#values_at(*keys) ⇒ Object
Returns a new Array containing values for the given keys
:
h = {foo: 0, bar: 1, baz: 2}
h.values_at(:baz, :foo) # => [2, 0]
The default values are returned for any keys that are not found:
h.values_at(:hello, :foo) # => [nil, 0]
2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 |
# File 'hash.c', line 2696
static VALUE
rb_hash_values_at(int argc, VALUE *argv, VALUE hash)
{
VALUE result = rb_ary_new2(argc);
long i;
for (i=0; i<argc; i++) {
rb_ary_push(result, rb_hash_aref(hash, argv[i]));
}
return result;
}
|