[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Array#slice! bug?

Gregory Seidman

2/25/2008 5:44:00 PM

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