[DOC] Fix the default limit
of String#split
We can't pass `nil` as the second parameter of `String#split`. Therefore, descriptions like "if limit is nil, ..." are not appropriate.
This commit is contained in:
parent
519b233695
commit
eb2b0c2a0d
Notes:
git
2024-11-19 03:16:06 +00:00
@ -12,7 +12,7 @@ When +field_sep+ is <tt>$;</tt>:
|
|||||||
the split occurs just as if +field_sep+ were given as that string
|
the split occurs just as if +field_sep+ were given as that string
|
||||||
(see below).
|
(see below).
|
||||||
|
|
||||||
When +field_sep+ is <tt>' '</tt> and +limit+ is +nil+,
|
When +field_sep+ is <tt>' '</tt> and +limit+ is +0+ (its default value),
|
||||||
the split occurs at each sequence of whitespace:
|
the split occurs at each sequence of whitespace:
|
||||||
|
|
||||||
'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
||||||
@ -21,7 +21,7 @@ the split occurs at each sequence of whitespace:
|
|||||||
''.split(' ') => []
|
''.split(' ') => []
|
||||||
|
|
||||||
When +field_sep+ is a string different from <tt>' '</tt>
|
When +field_sep+ is a string different from <tt>' '</tt>
|
||||||
and +limit+ is +nil+,
|
and +limit+ is +0+,
|
||||||
the split occurs at each occurrence of +field_sep+;
|
the split occurs at each occurrence of +field_sep+;
|
||||||
trailing empty substrings are not returned:
|
trailing empty substrings are not returned:
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ trailing empty substrings are not returned:
|
|||||||
'тест'.split('т') => ["", "ес"]
|
'тест'.split('т') => ["", "ес"]
|
||||||
'こんにちは'.split('に') => ["こん", "ちは"]
|
'こんにちは'.split('に') => ["こん", "ちは"]
|
||||||
|
|
||||||
When +field_sep+ is a Regexp and +limit+ is +nil+,
|
When +field_sep+ is a Regexp and +limit+ is +0+,
|
||||||
the split occurs at each occurrence of a match;
|
the split occurs at each occurrence of a match;
|
||||||
trailing empty substrings are not returned:
|
trailing empty substrings are not returned:
|
||||||
|
|
||||||
@ -47,12 +47,10 @@ in the returned array:
|
|||||||
|
|
||||||
'1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
|
'1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
|
||||||
|
|
||||||
As seen above, if +limit+ is +nil+,
|
As seen above, if +limit+ is +0+,
|
||||||
trailing empty substrings are not returned;
|
trailing empty substrings are not returned:
|
||||||
the same is true if +limit+ is zero:
|
|
||||||
|
|
||||||
'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
|
'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
|
||||||
'aaabcdaaa'.split('a', 0) # => ["", "", "", "bcd"]
|
|
||||||
|
|
||||||
If +limit+ is positive integer +n+, no more than <tt>n - 1-</tt>
|
If +limit+ is positive integer +n+, no more than <tt>n - 1-</tt>
|
||||||
splits occur, so that at most +n+ substrings are returned,
|
splits occur, so that at most +n+ substrings are returned,
|
||||||
@ -67,7 +65,7 @@ and trailing empty substrings are included:
|
|||||||
Note that if +field_sep+ is a \Regexp containing groups,
|
Note that if +field_sep+ is a \Regexp containing groups,
|
||||||
their matches are in the returned array, but do not count toward the limit.
|
their matches are in the returned array, but do not count toward the limit.
|
||||||
|
|
||||||
If +limit+ is negative, it behaves the same as if +limit+ was +nil+,
|
If +limit+ is negative, it behaves the same as if +limit+ was zero,
|
||||||
meaning that there is no limit,
|
meaning that there is no limit,
|
||||||
and trailing empty substrings are included:
|
and trailing empty substrings are included:
|
||||||
|
|
||||||
|
4
string.c
4
string.c
@ -9172,8 +9172,8 @@ literal_split_pattern(VALUE spat, split_type_t default_type)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* split(field_sep = $;, limit = nil) -> array
|
* split(field_sep = $;, limit = 0) -> array
|
||||||
* split(field_sep = $;, limit = nil) {|substring| ... } -> self
|
* split(field_sep = $;, limit = 0) {|substring| ... } -> self
|
||||||
*
|
*
|
||||||
* :include: doc/string/split.rdoc
|
* :include: doc/string/split.rdoc
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user