Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'diff-0.4/lib/algorithm/diff'
- a = 'testing
- sled
- 123
- testing'
- ab = a.dup
- b = 'testing
- sledding across the white snow
- 123error
- testing'
- diff = Diff.diff(a, b)
- offset = 0
- b_insert = '<b>'
- a_insert = '</b>'
- diff.each do |d|
- a.insert(d[1] + offset, b_insert + d[2])
- offset += b_insert.length
- a.insert(d[1] + d[2].length + offset, a_insert)
- offset += a_insert.length
- end
- puts "\nOriginal:"
- puts ab
- puts "\nChanged:"
- puts a, "\n"
Add Comment
Please, Sign In to add comment