Slide 145
Slide 145 text
String Diff
require "tempfile"
!
class String
def diff(other)
st = Tempfile.new("diff_self")
ot = Tempfile.new("diff_other")
st << self
ot << other
[st, ot].each { |t| t.flush }
`diff -u #{st.path} #{ot.path}`[/^@.+\z/m]
end
end
!
puts "one\ntwo\n".diff("one\nthree\n")
# >> @@ -1,2 +1,2 @@
# >> one
# >> -two
# >> +three