String#slice! changed behavior

Sun, 2 Jun 2002 07:40:43 +0900, Yukihiro Matsumoto matz@ruby-lang.org pisze:

“abcd”.slice(10) raises IndexError, so should “abcd”.slice!(/x/),
I thought.

So what about “abcd”.slice!(‘x’), “abcd”[‘x’] = ‘y’, “abcd”[/x/] = ‘y’
and finally “abcd”.sub!(/x/, ‘y’)? They all don’t raise exceptions.
I don’t say that they all should but that it’s somewhat inconsistent.

···


__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
__/
^^
QRCZAK

Hi,

···

In message “Re: String#slice! changed behavior” on 02/06/02, Marcin ‘Qrczak’ Kowalczyk qrczak@knm.org.pl writes:

“abcd”.slice(10) raises IndexError, so should “abcd”.slice!(/x/),
I thought.

So what about “abcd”.slice!(‘x’), “abcd”[‘x’] = ‘y’, “abcd”[/x/] = ‘y’
and finally “abcd”.sub!(/x/, ‘y’)? They all don’t raise exceptions.

The first three should raise exceptions. I will fix.

The last one “abcd”.sub!(/x/, ‘y’) should not, because its behavior is
“to replace the first occurrence of x if any”.

						matz.