зеркало из https://github.com/github/ruby.git
Add exception support in `Range#first`.
Closes: https://github.com/ruby/ruby/pull/2163
This commit is contained in:
Родитель
0eedec6867
Коммит
4e88e86928
3
range.c
3
range.c
|
@ -1012,6 +1012,9 @@ range_first(int argc, VALUE *argv, VALUE range)
|
|||
{
|
||||
VALUE n, ary[2];
|
||||
|
||||
if (NIL_P(RANGE_BEG(range))) {
|
||||
rb_raise(rb_eRangeError, "cannot get the first element of beginless range");
|
||||
}
|
||||
if (argc == 0) return RANGE_BEG(range);
|
||||
|
||||
rb_scan_args(argc, argv, "1", &n);
|
||||
|
|
|
@ -443,6 +443,8 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_equal("a", ("a"..nil).first)
|
||||
assert_raise(RangeError) { (0..nil).last }
|
||||
assert_raise(RangeError) { (0..nil).last(3) }
|
||||
assert_raise(RangeError) { (nil..0).first }
|
||||
assert_raise(RangeError) { (nil..0).first(3) }
|
||||
|
||||
assert_equal([0, 1, 2], (0..10).first(3.0))
|
||||
assert_equal([8, 9, 10], (0..10).last(3.0))
|
||||
|
|
Загрузка…
Ссылка в новой задаче