Sha256: eef4c4031dc9f42b314f8edd2d86a2672be8c5363d2f9cff710c86669dbc7ce2

Contents?: true

Size: 754 Bytes

Versions: 23

Compression:

Stored size: 754 Bytes

Contents

describe "String#sub with pattern, replacement" do
  it "returns a copy of self with all occurrences of pattern replaced with replacement" do
    "hello".sub(/[aeiou]/, '*').should == "h*llo"
    "hello".sub(//, ".").should == ".hello"
  end

  it "ignores a block if supplied" do
    "food".sub(/f/, "g") { "w" }.should == "good"
  end

  it "supports /i for ignoring case" do
    "Hello".sub(/h/i, "j").should == "jello"
    "hello".sub(/H/i, "j").should == "jello"
  end
end

describe "String#sub with pattern and block" do
  it "returns a copy of self with the first occurences of pattern replaces with block's return value" do
    "hi".sub(/./) { |s| s + ' ' }.should == "h i"
    "hi!".sub(/(.)(.)/) { |*a| a.inspect }.should == '["hi"]!'
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opal-0.3.43 spec/rubyspec/core/string/sub_spec.rb
opal-0.3.42 spec/core/string/sub_spec.rb
opal-0.3.41 spec/core/string/sub_spec.rb
opal-0.3.40 spec/core/string/sub_spec.rb
opal-0.3.39 spec/core/string/sub_spec.rb
opal-0.3.38 spec/core/string/sub_spec.rb
opal-0.3.37 spec/core/string/sub_spec.rb
opal-0.3.36 spec/core/string/sub_spec.rb
opal-0.3.35 spec/core/string/sub_spec.rb
opal-0.3.34 spec/core/string/sub_spec.rb
opal-0.3.33 spec/core/string/sub_spec.rb
opal-0.3.32 spec/core/string/sub_spec.rb
opal-0.3.31 spec/core/string/sub_spec.rb
opal-0.3.30 spec/core/string/sub_spec.rb
opal-0.3.29 spec/core/string/sub_spec.rb
opal-0.3.28 spec/core/string/sub_spec.rb
opal-0.3.27 spec/core/string/sub_spec.rb
opal-0.3.26 spec/core/string/sub_spec.rb
opal-0.3.25 spec/core/string/sub_spec.rb
opal-0.3.22 spec/core/string/sub_spec.rb