End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Range#to_a
rng.to_a → array
range.c
View on GitHub ↗
static VALUE
range_to_a(VALUE range)
{
if (NIL_P(RANGE_END(range))) {
rb_raise(rb_eRangeError, "cannot convert endless range to an array");
}
return rb_call_super(0, 0);
}
Returns an array containing the items in the range.
Example
(1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7] (1..).to_a #=> RangeError: cannot convert endless range to an array