mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
cfa40e225a
commit
bbe5ec7846
Notes:
git
2022-09-04 18:16:33 +09:00
2 changed files with 10 additions and 4 deletions
8
range.c
8
range.c
|
@ -1107,10 +1107,6 @@ rb_int_range_last(int argc, VALUE *argv, VALUE range)
|
|||
x = EXCL(range);
|
||||
|
||||
len_1 = rb_int_minus(e, b);
|
||||
if (FIXNUM_ZERO_P(len_1) || rb_num_negative_p(len_1)) {
|
||||
return rb_ary_new_capa(0);
|
||||
}
|
||||
|
||||
if (x) {
|
||||
e = rb_int_minus(e, ONE);
|
||||
len = len_1;
|
||||
|
@ -1119,6 +1115,10 @@ rb_int_range_last(int argc, VALUE *argv, VALUE range)
|
|||
len = rb_int_plus(len_1, ONE);
|
||||
}
|
||||
|
||||
if (FIXNUM_ZERO_P(len) || rb_num_negative_p(len)) {
|
||||
return rb_ary_new_capa(0);
|
||||
}
|
||||
|
||||
rb_scan_args(argc, argv, "1", &nv);
|
||||
n = NUM2LONG(nv);
|
||||
if (n < 0) {
|
||||
|
|
|
@ -8,6 +8,12 @@ describe "Range#last" do
|
|||
(1..5).last(3).should == [3, 4, 5]
|
||||
end
|
||||
|
||||
ruby_bug '#18994', '2.7'...'3.2' do
|
||||
it "returns the specified number if elements for single element inclusive range" do
|
||||
(1..1).last(1).should == [1]
|
||||
end
|
||||
end
|
||||
|
||||
it "returns an empty array for an empty Range" do
|
||||
(0...0).last(2).should == []
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue