Sha256: 73cbcccbb681e643cd36d2cc1efa4e7aac1058664ea3dd8edb0096b81089645c
Contents?: true
Size: 854 Bytes
Versions: 1
Compression:
Stored size: 854 Bytes
Contents
module SubDiff # Performs a {String#sub} or {String#gsub} replacement # while yielding each match "diff payload" to a block. # # The payload contains: # # match - the string matching the search. # prefix - the string preceding the match. # suffix - the string trailing the match. # replacement - the string replacing the match. # # This class uses some special global variables: $` and $'. # See http://ruby-doc.org/core-2.2.0/doc/globals_rdoc.html # # Used internally by {Sub}. # # @api private class Differ include Buildable def match(search, *args, replacement) string.send(diff_method, search) do |match| diff = { match: match, prefix: $`, suffix: $' } diff[:replacement] = match.sub(search, *args, &replacement) yield(diff) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sub_diff-1.1.1 | lib/sub_diff/differ.rb |