Method: Hash#to_a
- Defined in:
- hash.c
#to_a ⇒ Object
Returns a new Array of 2-element Array objects; each nested Array contains a key-value pair from self:
h = {foo: 0, bar: 1, baz: 2}
h.to_a # => [[:foo, 0], [:bar, 1], [:baz, 2]]
3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 |
# File 'hash.c', line 3397 static VALUE rb_hash_to_a(VALUE hash) { VALUE ary; ary = rb_ary_new_capa(RHASH_SIZE(hash)); rb_hash_foreach(hash, to_a_i, ary); return ary; } |