Method: MatchData#sub
- Defined in:
- lib/innate/regexp.rb
#sub(repl, capture_num = 1) ⇒ Object
Replace the matching part of the string with match interpolation.
If there are any captures, replaces the first one, otherwise replaces the whole match.
Interpolates %n to the corresponding capture.
71 72 73 74 |
# File 'lib/innate/regexp.rb', line 71 def sub(repl, capture_num = 1) cn = capture_num || 1 replace_capture self[cn] ? cn : 0, interpolate(repl) end |