Last active
April 12, 2016 17:10
-
-
Save mrhead/28119d4d0b94e34660479e3797086aa4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Very simple Ruby diff for strings. | |
# It works only on strings with the same number of lines, but it was perfect | |
# for my usecase where I was modifying templates saved in the database and I | |
# wanted to be sure that I am changing only what needs to be changed. | |
def differ(str_a, str_b) | |
str_a.lines.zip(str_b.lines) do |line_a, line_b| | |
if line_a != line_b | |
puts "< #{line_a}" | |
puts "> #{line_b}" | |
end | |
end | |
end | |
# example output | |
# < {{ order.item_name }} {{ order.total }} | |
# > {{ order.item_name }} {{ order.item_price }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment