mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2890 from jbreeden/sub_pattern_not_found
Don't crash if pattern not found for sub
This commit is contained in:
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user