Merge pull request #2890 from jbreeden/sub_pattern_not_found

Don't crash if pattern not found for sub
This commit is contained in:
Yukihiro "Matz" Matsumoto
2015-07-17 11:37:30 +09:00
+1
View File
@@ -111,6 +111,7 @@ class String
def sub(*args, &block)
if args.size == 2
pre, post = split(args[0], 2)
return self unless post # The sub target wasn't found in the string
pre + args[1].__sub_replace(pre, args[0], post) + post
elsif args.size == 1 && block
split(args[0], 2).join(block.call(args[0]))