Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9aa7833c1a0a
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9b66e03176a3
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 29, 2015

  1. Copy the full SHA
    de99986 View commit details
  2. Copy the full SHA
    586de02 View commit details
  3. Merge pull request #3475 from kachick/string-split

    String#split should trim tail empty strings when the limit is zero
    jc00ke committed Jul 29, 2015
    Copy the full SHA
    9b66e03 View commit details
Showing with 9 additions and 1 deletion.
  1. +3 −1 kernel/common/splitter.rb
  2. +6 −0 spec/ruby/core/string/split_spec.rb
4 changes: 3 additions & 1 deletion kernel/common/splitter.rb
Original file line number Diff line number Diff line change
@@ -32,7 +32,9 @@ def self.split(string, pattern, limit)
return [string.dup] if limit == 1
limited = true
else
tail_empty = true
if limit < 0
tail_empty = true
end
limited = false
end
end
6 changes: 6 additions & 0 deletions spec/ruby/core/string/split_spec.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,12 @@
"a\x00a b".split(' ').should == ["a\x00a", "b"]
end

describe "when limit is zero" do
it "ignores leading and continuous whitespace when string is a single space" do
" now's the time ".split(' ', 0).should == ["now's", "the", "time"]
end
end

it "splits between characters when its argument is an empty string" do
"hi!".split("").should == ["h", "i", "!"]
"hi!".split("", -1).should == ["h", "i", "!", ""]