Sha256: 9c305b493ab65c6d88cc26a2a4f79e292cc3823b0bd6da09ac4e3c7c1db42bcc

Contents?: true

Size: 571 Bytes

Versions: 2

Compression:

Stored size: 571 Bytes

Contents

module SubDiff
  class Sub < Struct.new(:differ)
    def diff(*args, &block)
      # Ruby 1.8.7 does not support additional args after * (splat)
      args.push(block)

      differ.diff(*args) do |builder, diff|
        diff!(builder, diff, args.first)
      end
    end

    private

    def diff!(builder, diff, search)
      builder << prefix(diff)
      builder.push(diff[:replacement], diff[:match])
      builder << suffix(diff, search)
    end

    def prefix(diff)
      diff[:prefix]
    end

    def suffix(diff, _search)
      diff[:suffix]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sub_diff-1.0.1 lib/sub_diff/sub.rb
sub_diff-1.0.0 lib/sub_diff/sub.rb