keys()
public
Returns a new array populated with the
keys from this hash. See also Hash#values.
h = { "a" => 100, "b" => 200, "c" => 300, "d" => 400 }
h.keys
Show source
VALUE
rb_hash_keys(VALUE hash)
{
VALUE keys;
st_index_t size = RHASH_SIZE(hash);
keys = rb_ary_new_capa(size);
if (size == 0) return keys;
if (ST_DATA_COMPATIBLE_P(VALUE)) {
st_table *table = RHASH(hash)->ntbl;
rb_gc_writebarrier_remember(keys);
RARRAY_PTR_USE(keys, ptr, {
size = st_keys(table, ptr, size);
});
rb_ary_set_len(keys, size);
}
else {
rb_hash_foreach(hash, keys_i, keys);
}
return keys;
}