Method: Enumerable#to_h
- Defined in:
- enum.c
#to_h(*args) ⇒ Hash
Returns the result of interpreting enum as a list of [key, value] pairs.
%i[hello world].each_with_index.to_h
# => {:hello => 0, :world => 1}
542 543 544 545 546 547 548 549 |
# File 'enum.c', line 542
static VALUE
enum_to_h(int argc, VALUE *argv, VALUE obj)
{
VALUE hash = rb_hash_new();
rb_block_call(obj, id_each, argc, argv, enum_to_h_i, hash);
OBJ_INFECT(hash, obj);
return hash;
}
|