class Diff::LCS::DiffCallbacks

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::DiffCallbacks.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::DiffCallbacks.new
method.
This callback object must be initialised and is used by the Diff::LCS#diff
=== Use
of the second sequence. The other two hunks are described similarly.
first sequence should be removed and replaced with the f from position 4
('+'). The third hunk says that the h at position 4 of the
says that the d at position 2 of the second sequence should be inserted
of the first sequence should be deleted ('-'). The second hunk
There are five hunks here. The first hunk says that the a at position 0
# [ ‘+’, 11, ‘t’ ] ] ]
# [ ‘+’, 10, ‘s’ ],
# [ ‘+’, 9, ‘r’ ],
# [ ‘-’, 9, ‘p’ ],
# [ [ ‘-’, 8, ‘n’ ], # 5
# [ [ ‘+’, 6, ‘k’ ] ], # 4
# [ ‘+’, 4, ‘f’ ] ],
# [ [ ‘-’, 4, ‘h’ ], # 3
# [ [ ‘+’, 2, ‘d’ ] ], # 2
# [ [ [ ‘-’, 0, ‘a’ ] ], # 1
# This example shows a simplified array format.
diffs = Diff::LCS.diff(seq1, seq2)
sequences. The hunk provides the full context for the changes.
addition or removal of a single element from one of the two tested
element in each hunk array is a single Change object representing the
element in the #diffs array is a hunk or hunk array, where each
This will produce a compound array of simple diff change objects. Each

def discard_a(event)

def discard_a(event)
  @hunk << Diff::LCS::Change.new('-', event.old_position, event.old_element)
end

def discard_b(event)

def discard_b(event)
  @hunk << Diff::LCS::Change.new('+', event.new_position, event.new_element)
end

def finish

is appended to the diff list.
Finalizes the diff process. If an unprocessed hunk still exists, then it
def finish
  finish_hunk
end

def finish_hunk

def finish_hunk
  @diffs << @hunk unless @hunk.empty?
  @hunk = []
end

def initialize # :yields self:

:yields self:
def initialize # :yields self:
  @hunk = []
  @diffs = []
  return unless block_given?
  begin
    yield self
  ensure
    finish
  end
end

def match(_event)

def match(_event)
  finish_hunk
end