From: nobu@... Date: 2017-03-02T06:08:02+00:00 Subject: [ruby-core:79857] [Ruby trunk Bug#13266][Rejected] Slicing in array producing wrong results Issue #13266 has been updated by Nobuyoshi Nakada. Description updated Status changed from Open to Rejected > Additionally, an empty array is returned when the starting index for an element range is at the end of the array. ---------------------------------------- Bug #13266: Slicing in array producing wrong results https://bugs.ruby-lang.org/issues/13266#change-63289 * Author: Aman Puri * Status: Rejected * Priority: Normal * Assignee: * Target version: * ruby -v: 2.3.1 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- ``` even_nums = [2,4,6,8,10] 2.3.1 :007 > even_nums[5,0] => [] # it must return nil as index is out of bound when slicing # it may be due to the code written in ruby.c =begin if (argc == 2) { if (SYMBOL_P(argv[0])) { rb_raise(rb_eTypeError, "Symbol as array index"); } beg = NUM2LONG(argv[0]); len = NUM2LONG(argv[1]); if (beg < 0) { beg += RARRAY(ary)->len; } return rb_ary_subseq(ary, beg, len); } =end # beg will store 5 in it and then this value is compared with RARRAY_LEN(ary) # in code it is defined that if (beg > RARRAY_LEN(ary)) return Qnil; # it must be corrected and checked with the index of the array rather then size of array 2.3.1 :008 > even_nums[6,0] => nil -- https://bugs.ruby-lang.org/ Unsubscribe: