Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'diff/lcs'
- require 'diff/lcs/hunk'
- data_old = [ 'hello', 'one', 'two', 'three', 'goodbye']
- data_new = [ 'hello', 'oNE', 'three', 'goodbye']
- diffs = Diff::LCS.diff(data_old, data_new)
- file_length_difference = 0
- oldhunk = nil
- hunk = nil
- output = ''
- diffs.each do |piece|
- begin
- hunk = Diff::LCS::Hunk.new(data_old, data_new, piece, 3, file_length_difference)
- file_length_difference = hunk.file_length_difference
- next unless oldhunk
- if hunk.overlaps?(oldhunk)
- hunk.unshift(oldhunk)
- else
- output << oldhunk.diff(:unified)
- end
- ensure
- oldhunk = hunk
- output << "\n"
- end
- end
- output << oldhunk.diff(:unified)
- output << "\n"
- puts output
Add Comment
Please, Sign In to add comment