Project

General

Profile

Bug #14845 ยป range_to_a.patch

mame (Yusuke Endoh), 06/13/2018 11:19 AM

View differences:

range.c
return Qnil;
}
/*
* call-seq:
* rng.to_a -> array
* rng.entries -> array
*
* Returns an array containing the items in <i>rng</i>.
*
* (1..7).to_a #=> [1, 2, 3, 4, 5, 6, 7]
* (1..).to_a #=> RangeError: cannot convert endless range to an array
*/
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);
}
static VALUE
range_enum_size(VALUE range, VALUE args, VALUE eobj)
{
......
rb_define_method(rb_cRange, "min", range_min, -1);
rb_define_method(rb_cRange, "max", range_max, -1);
rb_define_method(rb_cRange, "size", range_size, 0);
rb_define_method(rb_cRange, "to_a", range_to_a, 0);
rb_define_method(rb_cRange, "entries", range_to_a, 0);
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
test/ruby/test_range.rb
end
(a.."c").each {|x, &b| assert_nil(b)}
end
def test_to_a
assert_equal([1,2,3,4,5], (1..5).to_a)
assert_equal([1,2,3,4], (1...5).to_a)
assert_raise(RangeError) { (1..).to_a }
end
end
    (1-1/1)