From: Mark Hubbart Date: 2004-07-22T17:39:45+09:00 Subject: Re: [PATCH] was - Re: substring by range parameter (bug?) On Jul 21, 2004, at 9:32 PM, Ara.T.Howard wrote: > On Thu, 22 Jul 2004, Yukihiro Matsumoto wrote: > >> Hi, >> >> In message "[PATCH] was - Re: substring by range parameter (bug?)" >> on 04/07/22, "Ara.T.Howard" writes: >> >> |if you look at the source, it is clear that rb_range_beg_len intends >> to fail >> |with ranges like -1...-42. i think it is a bug that it does not. >> this patch >> |should fix it: >> >> I think I understand you, but not sure. Can you show me an example of >> wrong behavior? >> >> matz. > > note the second case: > > wrong: > > ~ > irb > irb(main):001:0> 'foobar'[-1..-1] > => "r" > irb(main):002:0> 'foobar'[-1..-2] > => "" > irb(main):003:0> 'foobar'[-1..-3] > => nil This seems right to me... aren't these two expressions equivalent? 'foobar'[-1..-2] ==>"" 'foobar'[5..4] ==>"" I admit that the beginning being lower than the end is a little strange at first, but I understood it to be an artifact of the range type. Since 1..2 includes the end number, it makes sense that the only way to get an empty string would be to go backwards... > right (patch applied): > > ~ > irb > irb(main):001:0> 'foobar'[-1..-1] > => "r" > irb(main):002:0> 'foobar'[-1..-2] > => nil > irb(main):003:0> 'foobar'[-1..-3] > => nil Correct me if I'm wrong, but doesn't that make it impossible to reference an empty string between characters? cheers, Mark