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: 64d73f9bd5fb
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 78edf6b7135b
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 12, 2015

  1. Updated String#sub/sub! specs for ArgumentError

    On MRI 2.1 and 2.2 String#sub behaviour when replacement is undefined and no
    block is passed is to raise an ArgumentError.
    fmfdias authored and Yorick Peterse committed Mar 12, 2015
    Copy the full SHA
    e6e1cb6 View commit details
  2. Update String#sub/sub! to raise ArgumentError.

    On MRI 2.1 and 2.2 String#sub behaviour when replacement is undefined and no
    block is passed is to raise an ArgumentError.
    fmfdias authored and Yorick Peterse committed Mar 12, 2015
    Copy the full SHA
    78edf6b View commit details
Showing with 14 additions and 2 deletions.
  1. +2 −2 kernel/common/string.rb
  2. +12 −0 spec/ruby/core/string/sub_spec.rb
4 changes: 2 additions & 2 deletions kernel/common/string.rb
Original file line number Diff line number Diff line change
@@ -1169,7 +1169,7 @@ def sub(pattern, replacement=undefined)

if undefined.equal? replacement
unless block_given?
return to_enum(:sub, pattern, replacement)
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
end
use_yield = true
tainted = false
@@ -1236,7 +1236,7 @@ def sub!(pattern, replacement=undefined)

if undefined.equal? replacement
unless block_given?
return to_enum(:sub, pattern, replacement)
raise ArgumentError, "method '#{__method__}': given 1, expected 2"
end
Rubinius.check_frozen
use_yield = true
12 changes: 12 additions & 0 deletions spec/ruby/core/string/sub_spec.rb
Original file line number Diff line number Diff line change
@@ -551,3 +551,15 @@
str.sub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true
end
end

describe "String#sub with pattern and without replacement and block" do
it "raises a ArgumentError" do
lambda { "abca".sub(/a/) }.should raise_error(ArgumentError)
end
end

describe "String#sub! with pattern and without replacement and block" do
it "raises a ArgumentError" do
lambda { "abca".sub!(/a/) }.should raise_error(ArgumentError)
end
end