From: D T Date: 2004-07-22T05:50:53+09:00 Subject: Re: substring by range parameter (bug?) > >for ranges, start must be <= end and -1 is not <= -2 > >eg. for the string "foobar": > > ---- --- ---- > char idx nidx > ---- --- ---- > f 0 -6 > o 1 -5 > o 2 -4 > b 3 -3 > a 4 -2 > r 5 -1 > > ~ > irb > irb(main):001:0> "foobar"[-2..-1] > => "ar" > irb(main):002:0> "foobar"[-6..-4] > => "foo" > irb(main):003:0> "foobar"[-3..-1] > => "bar" > >cheers. > Thanks. I know that. That is why I expect "foobar"[-1..-2] returns nil as "foobar"[-1..-3] did. But it returns an empty string instead of nil, it seems to me that this is a bug. In fact, if start is -n and end is < -(n+1), it will return nil. ( like -2..-4, -2..-5 ) The problem is only when start is -n and end is -(n+1), it always return empty string. (like -2..-3, -3..-4) How does it possible that a substring is empty string ? And the tricky part is, it do existe and you can re-assign to it too. like: s = "foobar"; s[-3..-4] = "xxx"; So, my question is, is this a bug, or special feature for substring when range is -n..-(n+1) ? _________________________________________________________________ Overwhelmed by debt? Find out how to �Dig Yourself Out of Debt� from MSN Money. http://special.msn.com/money/0407debt.armx