Array#slice! bug?

G

Gregory Seidman

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,278
Messages
2,571,180
Members
48,780
Latest member
altimist-patrick

Latest Threads

Top