class Diff::LCS::SDiffCallbacks
pp diffs.map { |e| e.to_a }
require ‘pp’
with:
The simplified array format used in the example above can be obtained
=== Simplified Array Format
cbo = Diff::LCS::SDiffCallbacks.new { |tcbo| Diff::LCS.LCS(seq1, seq2, tcbo) }
“fininishing” to be done, this has no effect on the state of the object.
Diff::LCS::SDiffCallbacks can be initialised with a block. As there is no
As with the other initialisable callback objects,
Diff::LCS.LCS(seq1, seq2, cbo)
cbo = Diff::LCS::SDiffCallbacks.new
method.
This callback object must be initialised and is used by the Diff::LCS#sdiff
=== 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::ContextDiffCallbacks. They may be compared as:
The result of this operation is similar to that of
# [ “+”, [ 10, nil], [ 11, “t” ] ] ]
# [ “!”, [ 9, “p”], [ 10, “s” ] ],
# [ “!”, [ 8, “n”], [ 9, “r” ] ],
# [ “=”, [ 7, “m”], [ 8, “m” ] ],
# [ “=”, [ 6, “l”], [ 7, “l” ] ],
# [ “+”, [ 6, nil], [ 6, “k” ] ],
# [ “=”, [ 5, “j”], [ 5, “j” ] ],
# [ “!”, [ 4, “h”], [ 4, “f” ] ],
# [ “=”, [ 3, “e”], [ 3, “e” ] ],
# [ “+”, [ 3, nil], [ 2, “d” ] ],
# [ “=”, [ 2, “c”], [ 1, “c” ] ],
# [ “=”, [ 1, “b”], [ 0, “b” ] ],
# [ [ “-”, [ 0, “a”], [ 0, nil ] ],
# This example shows a simplified array format.
diffs = Diff::LCS.sdiff(seq1, seq2)
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)
- > new
old < -
before | after
same samesdiff
.
and their minimized differences side by side, just like the Unix utility
will compute and display the necessary components to show two sequences
The diffset produced by this callback, when provided to Diff::LCS#sdiff,
for a discarded object.
changed <strong>and unchanged</strong> objects. nil
will be substituted
by SDiffCallbacks, both old and new objects will be presented for both
the #diffs array is a single ContextChange. In the set of #diffs provided
This will produce a simple array of diff change objects. Each element in
def change(event)
def change(event) @diffs << Diff::LCS::ContextChange.simplify(event) end
def discard_a(event)
def discard_a(event) @diffs << Diff::LCS::ContextChange.simplify(event) end
def discard_b(event)
def discard_b(event) @diffs << Diff::LCS::ContextChange.simplify(event) end
def initialize # :yields: self
def initialize # :yields: self @diffs = [] yield self if block_given? end
def match(event)
def match(event) @diffs << Diff::LCS::ContextChange.simplify(event) end