Skip to content

Commit eb2b0c2

Browse files
kyanaginobu
authored andcommitted
[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.
1 parent 519b233 commit eb2b0c2

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

doc/string/split.rdoc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ When +field_sep+ is <tt>$;</tt>:
1212
the split occurs just as if +field_sep+ were given as that string
1313
(see below).
1414

15-
When +field_sep+ is <tt>' '</tt> and +limit+ is +nil+,
15+
When +field_sep+ is <tt>' '</tt> and +limit+ is +0+ (its default value),
1616
the split occurs at each sequence of whitespace:
1717

1818
'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
@@ -21,7 +21,7 @@ the split occurs at each sequence of whitespace:
2121
''.split(' ') => []
2222

2323
When +field_sep+ is a string different from <tt>' '</tt>
24-
and +limit+ is +nil+,
24+
and +limit+ is +0+,
2525
the split occurs at each occurrence of +field_sep+;
2626
trailing empty substrings are not returned:
2727

@@ -33,7 +33,7 @@ trailing empty substrings are not returned:
3333
'тест'.split('т') => ["", "ес"]
3434
'こんにちは'.split('に') => ["こん", "ちは"]
3535

36-
When +field_sep+ is a Regexp and +limit+ is +nil+,
36+
When +field_sep+ is a Regexp and +limit+ is +0+,
3737
the split occurs at each occurrence of a match;
3838
trailing empty substrings are not returned:
3939

@@ -47,12 +47,10 @@ in the returned array:
4747

4848
'1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
4949

50-
As seen above, if +limit+ is +nil+,
51-
trailing empty substrings are not returned;
52-
the same is true if +limit+ is zero:
50+
As seen above, if +limit+ is +0+,
51+
trailing empty substrings are not returned:
5352

5453
'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
55-
'aaabcdaaa'.split('a', 0) # => ["", "", "", "bcd"]
5654

5755
If +limit+ is positive integer +n+, no more than <tt>n - 1-</tt>
5856
splits occur, so that at most +n+ substrings are returned,
@@ -67,7 +65,7 @@ and trailing empty substrings are included:
6765
Note that if +field_sep+ is a \Regexp containing groups,
6866
their matches are in the returned array, but do not count toward the limit.
6967

70-
If +limit+ is negative, it behaves the same as if +limit+ was +nil+,
68+
If +limit+ is negative, it behaves the same as if +limit+ was zero,
7169
meaning that there is no limit,
7270
and trailing empty substrings are included:
7371

string.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9172,8 +9172,8 @@ literal_split_pattern(VALUE spat, split_type_t default_type)
91729172

91739173
/*
91749174
* call-seq:
9175-
* split(field_sep = $;, limit = nil) -> array
9176-
* split(field_sep = $;, limit = nil) {|substring| ... } -> self
9175+
* split(field_sep = $;, limit = 0) -> array
9176+
* split(field_sep = $;, limit = 0) {|substring| ... } -> self
91779177
*
91789178
* :include: doc/string/split.rdoc
91799179
*

0 commit comments

Comments
 (0)