mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Let String#slice! return nil (#3533)
Returns `nil` instead of an empty string when non-integer number is given (to make it 2.7 compatible).
This commit is contained in:
parent
0d78390bfb
commit
f0ddbd502c
Notes:
git
2020-09-11 14:34:35 +09:00
Merged-By: soutaro <matsumoto@soutaro.com>
2 changed files with 6 additions and 1 deletions
5
string.c
5
string.c
|
@ -4961,7 +4961,10 @@ rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
|
|||
return Qnil;
|
||||
case Qfalse:
|
||||
beg = NUM2LONG(indx);
|
||||
goto num_index;
|
||||
if (!(p = rb_str_subpos(str, beg, &len))) return Qnil;
|
||||
if (!len) return Qnil;
|
||||
beg = p - RSTRING_PTR(str);
|
||||
goto subseq;
|
||||
default:
|
||||
goto num_index;
|
||||
}
|
||||
|
|
|
@ -1588,8 +1588,10 @@ CODE
|
|||
a = S("FooBar")
|
||||
if @aref_slicebang_silent
|
||||
assert_nil( a.slice!(6) )
|
||||
assert_nil( a.slice!(6r) )
|
||||
else
|
||||
assert_raise(IndexError) { a.slice!(6) }
|
||||
assert_raise(IndexError) { a.slice!(6r) }
|
||||
end
|
||||
assert_equal(S("FooBar"), a)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue