Guest User

Untitled

a guest
Feb 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. require 'diff-0.4/lib/algorithm/diff'
  2.  
  3. a = 'testing
  4. sled
  5. 123
  6. testing'
  7. ab = a.dup
  8. b = 'testing
  9. sledding across the white snow
  10. 123error
  11. testing'
  12. diff = Diff.diff(a, b)
  13. offset = 0
  14. b_insert = '<b>'
  15. a_insert = '</b>'
  16. diff.each do |d|
  17. a.insert(d[1] + offset, b_insert + d[2])
  18. offset += b_insert.length
  19. a.insert(d[1] + d[2].length + offset, a_insert)
  20. offset += a_insert.length
  21. end
  22. puts "\nOriginal:"
  23. puts ab
  24. puts "\nChanged:"
  25. puts a, "\n"
Add Comment
Please, Sign In to add comment