Jordan Callicoat wrote:

> Taking your example, "'asd'[-10..-1]", this means
> 'asd'[-7..2] when you de-sugar it. Now in the other case,
> "'asd'[0...10]", once you reach #length-1, you can stop and return
> 0..#length-1. But with 'asd'[-7..2], what are you supposed to do when
> the start index is less than the first index (0)? Well, you could skip
> ahead to the first index, sure, but it makes just as much sense (if
> not more) to return nil/empty string. Same goes for cases such as
> 'asd'[-2..-3] (i.e., 'asd'[1..0]), where the start index is greater
> than the end index.

IMHO, the main goal of such a construct (some_string[-10..-1]) - to 
return last 10 chars from some_string. And in this case - returning 
'asd' for 'asd'[-10..-1] seems to be as logical as returning 'asd' for 
'asd' for [0..10] (as implemented now).

right now (1.8.6) we have:
1) 'asd'[0..10] => 'asd'
2) 'asd'[2..1]  => ''
3) 'asd'[-1..-2] => ''
-BUT-
4) 'asd'[-10..-1] => nil

I think, that by a "Principle of Least Astonishment" (c) we can unify 
that cases - i.e. to return either 'asd' or nil in cases 1) and 4). All 
that we need - adjust start index of the range to 0, if negative - right 
after de-sugar.
-- 
Posted via http://www.ruby-forum.com/.