1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Improve documentation for 'text '.split

The documentation didn't mention trailing spaces and the
example only demonstrated the case with leading spaces.
[Fix GH-1845]

From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62881 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-21 16:02:26 +00:00
parent eb02dd3c05
commit 7506fde3e9

View file

@ -7641,8 +7641,8 @@ split_string(VALUE result, VALUE str, long beg, long len, long empty_count)
* *
* If <i>pattern</i> is a <code>String</code>, then its contents are used as * If <i>pattern</i> is a <code>String</code>, then its contents are used as
* the delimiter when splitting <i>str</i>. If <i>pattern</i> is a single * the delimiter when splitting <i>str</i>. If <i>pattern</i> is a single
* space, <i>str</i> is split on whitespace, with leading whitespace and runs * space, <i>str</i> is split on whitespace, with leading and trailing
* of contiguous whitespace characters ignored. * whitespace and runs of contiguous whitespace characters ignored.
* *
* If <i>pattern</i> is a <code>Regexp</code>, <i>str</i> is divided where the * If <i>pattern</i> is a <code>Regexp</code>, <i>str</i> is divided where the
* pattern matches. Whenever the pattern matches a zero-length string, * pattern matches. Whenever the pattern matches a zero-length string,
@ -7665,8 +7665,8 @@ split_string(VALUE result, VALUE str, long beg, long len, long empty_count)
* When the input +str+ is empty an empty Array is returned as the string is * When the input +str+ is empty an empty Array is returned as the string is
* considered to have no fields to split. * considered to have no fields to split.
* *
* " now's the time".split #=> ["now's", "the", "time"] * " now's the time ".split #=> ["now's", "the", "time"]
* " now's the time".split(' ') #=> ["now's", "the", "time"] * " now's the time ".split(' ') #=> ["now's", "the", "time"]
* " now's the time".split(/ /) #=> ["", "now's", "", "the", "time"] * " now's the time".split(/ /) #=> ["", "now's", "", "the", "time"]
* "1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"] * "1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"]
* "hello".split(//) #=> ["h", "e", "l", "l", "o"] * "hello".split(//) #=> ["h", "e", "l", "l", "o"]