Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Enumerable#to_a
to_a(*args) → array
enum.c
View on GitHub ↗
static VALUE
enum_to_a(int argc, VALUE *argv, VALUE obj)
{
VALUE ary = rb_ary_new();
rb_block_call_kw(obj, id_each, argc, argv, collect_all, ary, RB_PASS_CALLED_KEYWORDS);
return ary;
}
Returns an array containing the items in self:
Example
(0..4).to_a # => [0, 1, 2, 3, 4]