Skip to content

Instantly share code, notes, and snippets.

@mrhead
Last active April 12, 2016 17:10
Show Gist options
  • Save mrhead/28119d4d0b94e34660479e3797086aa4 to your computer and use it in GitHub Desktop.
Save mrhead/28119d4d0b94e34660479e3797086aa4 to your computer and use it in GitHub Desktop.
# 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