@@ -47,4 +47,96 @@ class String
4747 def initialize(str = '', encoding: nil, capacity: nil)
4848 Primitive.rb_str_init(str, encoding, capacity)
4949 end
50+
51+ # call-seq:
52+ # split(separator = $;, limit = nil) -> array
53+ # split(separator = $;, limit = nil) {|substring| ... } -> self
54+ #
55+ # Returns an array of substrings of +self+
56+ # that are the result of splitting +self+
57+ # at each occurrence of the given +separator+.
58+ #
59+ # When argument +separator+ is <tt>$;</tt>:
60+ #
61+ # - If <tt>$;</tt> is +nil+ (its default value),
62+ # the split occurs just as if +separator+ were given as a space character
63+ # (see below).
64+ #
65+ # - If <tt>$;</tt> is a string,
66+ # the split ocurs just as if +separator+ were given as that string
67+ # (see below).
68+ #
69+ # When argument +separator+ is <tt>' '</tt> and argument +limit+ is +nil+,
70+ # the split occurs at each sequence of whitespace:
71+ #
72+ # 'abc def ghi'.split(' ') # => ["abc", "def", "ghi"]
73+ # "abc \n\tdef\t\n ghi".split(' ') # => ["abc", "def", "ghi"]
74+ # 'abc def ghi'.split(' ') # => ["abc", "def", "ghi"]
75+ # ''.split(' ') # => []
76+ #
77+ # When argument +separator+ is a string different from <tt>' '</tt>
78+ # and argument +limit+ is +nil+,
79+ # the split occurs at each occurrence of the separator;
80+ # trailing empty substrings are not returned:
81+ #
82+ # 'abracadabra'.split('ab') # => ["", "racad", "ra"]
83+ # 'aaabcdaaa'.split('a') # => ["", "", "", "bcd"]
84+ # ''.split('a') # => []
85+ # '3.14159'.split('1') # => ["3.", "4", "59"]
86+ # '!@#$%^$&*($)_+'.split('$') # => ["!@#", "%^", "&*(", ")_+"]
87+ # 'тест'.split('т') # => ["", "ес"]
88+ # 'こんにちは'.split('に') # => ["こん", "ちは"]
89+ #
90+ # When argument +separator+ is a Regexp and argument +limit+ is +nil+,
91+ # the split occurs at each occurrence of a match;
92+ # trailing empty substrings are not returned:
93+ #
94+ # 'abracadabra'.split(/ab/) # => ["", "racad", "ra"]
95+ # 'aaabcdaaa'.split(/a/) # => ["", "", "", "bcd"]
96+ # 'aaabcdaaa'.split(//) # => ["a", "a", "a", "b", "c", "d", "a", "a", "a"]
97+ # '1 + 1 == 2'.split(/\W+/) # => ["1", "1", "2"]
98+ #
99+ # If the \Regexp contains groups, their matches are also included
100+ # in the returned array:
101+ #
102+ # '1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
103+ #
104+ # As seen above, if argument +limit+ is +nil+,
105+ # trailing empty substrings are not returned;
106+ # the same is true if +limit+ is zero:
107+ #
108+ # 'aaabcdaaa'.split('a') # => ["", "", "", "bcd"]
109+ # 'aaabcdaaa'.split('a', 0) # => ["", "", "", "bcd"]
110+ #
111+ # If +limit+ is positive integer +n+, no more than <tt>n - 1-</tt>
112+ # splits occur, so that at most +n+ substrings are returned,
113+ # and trailing empty substrings are included:
114+ #
115+ # 'aaabcdaaa'.split('a', 1) # => ["aaabcdaaa"]
116+ # 'aaabcdaaa'.split('a', 2) # => ["", "aabcdaaa"]
117+ # 'aaabcdaaa'.split('a', 5) # => ["", "", "", "bcd", "aa"]
118+ # 'aaabcdaaa'.split('a', 7) # => ["", "", "", "bcd", "", "", ""]
119+ # 'aaabcdaaa'.split('a', 8) # => ["", "", "", "bcd", "", "", ""]
120+ #
121+ # Note that if +separator+ is a \Regexp containing groups,
122+ # their matches are in the returned array, but do not count toward the limit.
123+ #
124+ # If +limit+ is negative, it behaves the same as if +limit+ was +nil+,
125+ # meaning that there is no limit,
126+ # and trailing empty substrings are included:
127+ #
128+ # 'aaabcdaaa'.split('a', -1) # => ["", "", "", "bcd", "", "", ""]
129+ #
130+ # If a block is given, it is called with each substring:
131+ #
132+ # 'abc def ghi'.split(' ') {|substring| p substring }
133+ #
134+ # Output:
135+ #
136+ # "abc"
137+ # "def"
138+ # "ghi"
139+ #
140+ def split; end
141+
50142end
0 commit comments