Method: Diff::LCS.diff
- Defined in:
- lib/gems/diff-lcs-1.1.2/lib/diff/lcs.rb
.diff(seq1, seq2, callbacks = nil, &block) ⇒ Object
Diff::LCS.diff computes the smallest set of additions and deletions necessary to turn the first sequence into the second, and returns a description of these changes.
See Diff::LCS::DiffCallbacks for the default behaviour. An alternate behaviour may be implemented with Diff::LCS::ContextDiffCallbacks. If a Class argument is provided for callbacks, #diff will attempt to initialise it. If the callbacks object (possibly initialised) responds to #finish, it will be called.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/gems/diff-lcs-1.1.2/lib/diff/lcs.rb', line 254 def diff(seq1, seq2, callbacks = nil, &block) # :yields diff changes: callbacks ||= Diff::LCS::DiffCallbacks if callbacks.kind_of?(Class) cb = callbacks.new rescue callbacks callbacks = cb end traverse_sequences(seq1, seq2, callbacks) callbacks.finish if callbacks.respond_to?(:finish) if block_given? res = callbacks.diffs.map do |hunk| if hunk.kind_of?(Array) hunk = hunk.map { |block| yield block } else yield hunk end end res else callbacks.diffs end end |