我想知道两个字符串之间的区别,我正在使用 diff-lcs 来做到这一点。但是,我无法解析输出。
require 'diff-lcs'
a = 'abcdef'
b = 'abcsef'
diffs = Diff::LCS.diff(a,b)
puts diffs.inspect
==> [[#<Diff::LCS::Change:0x0000010106dcc0 @action="-", @position=3, @element="d">, #<Diff::LCS::Change:0x0000010106db30 @action="+", @position=3, @element="s">], [#<Diff::LCS::Change:0x0000010106d360 @action="-", @position=6, @element="">]]
我只想输出字符差异,所以'd'和's'。有没有办法从该输出中提取@element?
谢谢