class Diff::LCS::ContextDiffCallbacks

pp diffs.map { |e| e.map { |f| f.to_a } }
require ‘pp’
with:
The simplified array format used in the example above can be obtained
=== Simplified Array Format
The necessary #finish call will be made.
cbo = Diff::LCS::ContextDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
changes will not be visible. Alternatively, can be used as:
Note that the call to #finish is absolutely necessary, or the last set of
cbo.finish
Diff::LCS.LCS(seq1, seq2, cbo)
cbo = Diff::LCS::ContextDiffCallbacks.new
Diff::LCS#diff or Diff::LCS#sdiff methods.
This callback object must be initialised and can be used by the
=== Use
s == c # -> true
c = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextDiffCallbacks).flatten(1)
s = Diff::LCS.sdiff(seq1, seq2).reject { |e| e.action == “=” }
Diff::LCS::SDiffCallbacks. They may be compared as:
The result of this operation is similar to that of
potentially “mismatched” pairs of additions and deletions.
presentation, because changed items are shown as changes (“!”) instead of
The five hunks are still present, but are significantly shorter in total
# [ “+”, [ 10, nil ], [ 11, “t” ] ] ] ]
# [ “!”, [ 9, “p” ], [ 10, “s” ] ],
# [ [ “!”, [ 8, “n” ], [ 9, “r” ] ], # 5
# [ [ “+”, [ 6, nil ], [ 6, “k” ] ] ], # 4
# [ [ “!”, [ 4, “h” ], [ 4, “f” ] ] ], # 3
# [ [ “+”, [ 3, nil ], [ 2, “d” ] ] ], # 2
# [ [ [ “-”, [ 0, “a” ], [ 0, nil ] ] ], # 1
# This example shows a simplified array format.
diffs = Diff::LCS.sdiff(seq1, seq2, Diff::LCS::ContextCallbacks)
results like:
This callback can also be used with Diff::LCS#sdiff, which will produce
related set of changes, they are still shown individually.
The five hunks shown are comprised of individual changes; if there is a
# [ ‘+’, [ 10, nil ], [ 11, ‘t’ ] ] ] ]
# [ ‘+’, [ 10, nil ], [ 10, ‘s’ ] ],
# [ ‘-’, [ 9, ‘p’ ], [ 10, nil ] ],
# [ ‘+’, [ 9, nil ], [ 9, ‘r’ ] ],
# [ [ ‘-’, [ 8, ‘n’ ], [ 9, nil ] ], # 5
# [ [ ‘+’, [ 6, nil ], [ 6, ‘k’ ] ] ], # 4
# [ ‘+’, [ 5, nil ], [ 4, ‘f’ ] ] ],
# [ [ ‘-’, [ 4, ‘h’ ], [ 4, nil ] ], # 3
# [ [ ‘+’, [ 3, nil ], [ 2, ‘d’ ] ] ], # 2
# [ [ [ ‘-’, [ 0, ‘a’ ], [ 0, nil ] ] ], # 1
# This example shows a simplified array format.
diffs = Diff::LCS.diff(seq1, seq2, Diff::LCS::ContextDiffCallbacks)
seq2 = %w(b c d e f j k l m r s t)
seq1 = %w(a b c e h j l m n p)
discarded object.
will be presented for changed objects. nil will be substituted for a
“hunk” provides the full context for the changes. Both old and new objects
that contains both the old index and new index values for the change. The
“hunk” array is a single change. Each change is a Diff::LCS::ContextChange
element in the #diffs array is a “hunk” array, where each element in each
This will produce a compound array of contextual diff change objects. Each

def change(event)

def change(event)
  @hunk << Diff::LCS::ContextChange.simplify(event)
end

def discard_a(event)

def discard_a(event)
  @hunk << Diff::LCS::ContextChange.simplify(event)
end

def discard_b(event)

def discard_b(event)
  @hunk << Diff::LCS::ContextChange.simplify(event)
end