On Fri, 23 Jul 2004, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: [PATCH] was - Re: substring by range parameter (bug?)" > on 04/07/22, "Ara.T.Howard" <ahoward / noaa.gov> writes: > > |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 > | > | 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 > > Now I fully understand. I will commit your fix. Can you prepare > ChangeLog entry for this fix? > > matz. tanaka has pointed out that this patch causes test failures. however, it does seem to be a bug - in fact negative beg/end in ranges does many odd things: ~/build/ruby > irb irb(main):001:0> (-1..-2).include? -1 => false irb(main):002:0> (-1..-2).include? -2 => false so perhaps this problem is bigger than DT initially suggested. it seems like Range#initialize should throw and error if beg > end (after mapping negative -> positive for cases like (5..-3)) but this would be a massive change... i am happy to contribute, but what do you suggest? kind regards. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================