Sha256: 279734bb79a324ea564fe5dc919ad3898b521ee16d7db07dcf3d13bfa5fb9b89

Contents?: true

Size: 462 Bytes

Versions: 1

Compression:

Stored size: 462 Bytes

Contents

module SubDiff
  class Differ < Struct.new(:builder, :type)
    extend Forwardable

    def_delegators :builder, :string

    def each_diff(*args)
      # Ruby 1.8.7 does not support additional args after * (splat)
      block = args.pop

      string.send(type, args.first) do |match|
        diff = { :match => match, :prefix => $`, :suffix => $' }
        diff[:replacement] = match.sub(*args, &block)
        yield(builder, diff)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sub_diff-1.0.2 lib/sub_diff/differ.rb