From: "Ara.T.Howard" Date: 2005-07-22T13:20:59+09:00 Subject: Re: Odd Array#[x..y] return values On Fri, 22 Jul 2005, Daniel Berger wrote: > Ara.T.Howard wrote: >> On Fri, 22 Jul 2005, Daniel Berger wrote: >> >>> Hi all, >>> >>> Ruby 1.8.2 >>> >>> Consider: >>> >>> irb(main):001:0> a = [] >>> => [] >>> irb(main):002:0> a[0..1] >>> => [] >> >> start at a legitimate index and continue with every possible index until the >> end, not matter where that is >> >>> irb(main):003:0> a[-2..-1] >>> => nil >> >> start at a illegitimate index and return that there cannot be anything after >> this - ergo 'nil' >> >>> Why does the first return [] and the second return nil? >> >> or at least that makes sense to me... >> >> cheers. >> >> -a > > Please explain how one is "legitimate" and the other is not. In both > cases, the indices do not exist. if you are thinking in terms of 'c' - which i tend to - an offset of zero from a thing is the same as the thing. but that clearly is not what's going on here. i think you are right to call that a bug. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================