# Array#slice! bug?

**URL:** <https://www.ruby-forum.com/t/array-slice-bug/130134>\
**Category:** Ruby\
**Created:** [February 25, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/array-slice-bug/130134 "2008-02-25T18:44:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pie-r-squared](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c77e96/32.png) [@pie-r-squared](https://www.ruby-forum.com/u/pie-r-squared)\
**Post date:** [February 25, 2008, 6:44pm UTC](https://www.ruby-forum.com/t/array-slice-bug/130134/1 "2008-02-25T18:44:35Z")

</div>

irb(main):001:0\> y = [1,2,3,4,5]  
=\> [1, 2, 3, 4, 5]  
irb(main):002:0\> y.slice! -7, 7  
=\> nil  
irb(main):003:0\> y  
=\> [1, 2, 3]  
irb(main):004:0\> y.slice! -7, 7  
IndexError: index -4 out of array  
from (irb):4:in `slice!’  
from (irb):4  
from :0  
irb(main):005:0\> y  
=\> [1, 2, 3]  
irb(main):006:0\>  
% ruby -v  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-darwin]  
%

Does this make sense to anyone? It appears that a negative index larger  
than the length of the array will wrap around… once. But when it wraps  
around, it returns nil, implying that it didn’t do anything, but still  
removes elements. When it would have to wrap around more than once,  
however, it correctly raises an IndexError.

Is this a bug? A poorly documented “feature”? What’s going on?

–Greg
