From: Austin Ziegler Date: 2004-03-18T13:37:18+09:00 Subject: Re: Slice or Value of Empty Array On Thu, 26 Feb 2004 04:21:20 +0900, Jim Freeze wrote: > On Thursday, 26 February 2004 at 3:56:57 +0900, Austin Ziegler wrote: >> On Thu, 26 Feb 2004 03:34:03 +0900, Jim Freeze wrote: >>> I am puzzling about the following: >> (reformatted) >> p [][0..0] # => [] >> p [][0..-1] # => [] >> p [][-1..-1] # => nil >>> If ary[n..n] returns a slice, then why does a[0..0] give me an empty >>> array and a[-1..-1] give me nil? >> Matz explained this some time ago. I think it has something to do with >> indexes sitting *between* elements in Ruby arrays, and the last element >> being precached as empty. >> >> I'm not sure if that makes any sense... > Hmm, vaguely. Do you have the reference? [ruby-talk:24773] Sorry it took so long for me to get back to you on this. I'm not sure why it quite works the way that it does for [][-1..-1], but that explains the concept in general. -austin -- austin ziegler * austin@halostatue.ca * Toronto, ON, Canada software designer * pragmatic programmer * 2004.03.17 * 23.33.28