module SubDiff class Gsub < Sub private def process(_builder, diff, _search) super last_prefix << prefix(diff) << diff[:match] end def last_prefix @last_prefix ||= '' end def prefix(_diff) super.sub(last_prefix, '') end def suffix(_diff, search) matcher = suffix_matcher(search) super unless super.send(matcher, search) end def suffix_matcher(search) search.is_a?(Regexp) ? :match : :include? end end end