Issue #5120 has been updated by matz (Yukihiro Matsumoto).

Status changed from Assigned to Rejected

At least some of your points are rational. Those behaviors are inherited from Perl.
I don't think we can change the behavior. We are not going to break existing code for the sake of consistency.

Matz.


----------------------------------------
Feature #5120: String#split needs to be logical
https://bugs.ruby-lang.org/issues/5120#change-70480

* Author: alexeymuranov (Alexey Muranov)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: Next Major
----------------------------------------
I would call this a bug, but i am new to Ruby, so i report this as a feature request.

Here are examples showing a surprising and inconsistent behavior of String#split method:

"aa".split('a')  # => []
"aab".split('a')  # => ["", "", "b"]

"aaa".split('aa')  # => ["", "a"] 
"aaaa".split('aa')  # => []
"aaaaa".split('aa')  # => ["", "", "a"] 

"".split('')  # => []
"a".split('')  # => ["a"]

What is the definition of *split*?
In my opinion, there should be given a simple one that would make it clear what to expect.
For example:

  str1.split(str2) returns a maximal array of non-empty substrings of str1 which can be concatenated with copies of str2 to form str1.

Additional precisions can be made to this definition to make clear what to expect as the result of "baaab".split("aa").

Thanks for attention.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>