Method: Diff::LCS.LCS
- Defined in:
- lib/gems/diff-lcs-1.1.2/lib/diff/lcs.rb
.LCS(seq1, seq2, &block) ⇒ Object
Given two sequenced Enumerables, LCS returns an Array containing their longest common subsequences.
lcs = Diff::LCS.LCS(seq1, seq2)
This array whose contents is such that:
lcs.each_with_index do |ee, ii|
assert(ee.nil? || (seq1[ii] == seq2[ee]))
end
If a block is provided, the matching subsequences will be yielded from seq1 in turn and may be modified before they are placed into the returned Array of subsequences.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs.rb', line 230 def LCS(seq1, seq2, &block) #:yields seq1[ii] for each matched: matches = Diff::LCS.__lcs(seq1, seq2) ret = [] matches.each_with_index do |ee, ii| unless matches[ii].nil? if block_given? ret << (yield seq1[ii]) else ret << seq1[ii] end end end ret end |