Sha256: 4d03c77eae52c255a779f3a3b84c583290024201fff9831e2a828cd5b1c466f3
Contents?: true
Size: 1.27 KB
Versions: 10
Compression:
Stored size: 1.27 KB
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 it "converts and supports back references in replacement string" do "javascript".sub(/(j).*(s).*/, '.\\1\\2').should == '.js' 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 it "should set the global match variable $~ inside block" do match_datas = [] "hello".sub(/(.)./) { match_datas << $~; $~[1].succ }.should == "illo" match_datas.length.should == 1 match_datas[0].length.should == 2 match_datas[0].should == ["he", "h"] end it "should set the global match variable $& inside block" do "hello".sub(/./) { "#{$&} " }.should == "h ello" end end
Version data entries
10 entries across 10 versions & 1 rubygems