From: Bertram Scharpf Date: 2009-08-03T09:11:11+09:00 Subject: Re: Inconsistency in Array#[] Hi, Am Montag, 03. Aug 2009, 05:50:10 +0900 schrieb Wojciech Piekutowski: > Disclaimer: I know what docs say, but I'd prefer a different > behaviour. I want to understand why this design decision was made. > > a = [1,2,3,4,5] > a[-10,10] #=> nil > > I got nil, but looking from -10 to 0 there are 5 elements, in > other words in the range (-10, 0> there are 5 elements, like in case > 1. > > I expected I'd get the same result as in 1 (yes, no additional nils, > just the whole array). I think this isn't really complying with the > principle of the least surprise. In the end, it is probably a matter of taste but I agree with you. I would even prefer a behaviour like this: a[3,-3] #=> [4,3,2] This would be the least surprise to me. I'm pleading for years for an `Array#notempty?' method analogous to `Numeric#nonzero?' which would be a one-liner in C. But that seems to be a real imposition on the developers community. Bertram ________________________________________________________________ VALUE rb_ary_notempty( ary) VALUE ary; { return RARRAY( ary)->len == 0 ? Qnil : ary; } -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de