lib/tdiff/tdiff.rb in tdiff-0.2.0 vs lib/tdiff/tdiff.rb in tdiff-0.3.0

- old
+ new

@@ -16,23 +16,20 @@ def tdiff_each_child(node,&block) node.each(&block) if node.kind_of?(Enumerable) end # - # Default method which compares two nodes. + # Default method which compares nodes. # - # @param [Object] original_node - # A node from the original tree. - # - # @param [Object] new_node + # @param [Object] node # A node from the new tree. # # @return [Boolean] - # Specifies whether the two nodes are equal. + # Specifies whether the nodes are equal. # - def tdiff_equal(original_node,new_node) - original_node == new_node + def tdiff_equal(node) + self == node end # # Finds the differences between `self` and another tree. # @@ -53,11 +50,11 @@ # def tdiff(tree,&block) return enum_for(:tdiff,tree) unless block # check if the nodes differ - unless tdiff_equal(self,tree) + unless tdiff_equal(tree) yield '-', self yield '+', tree return self end @@ -65,11 +62,11 @@ x = enum_for(:tdiff_each_child,self) y = enum_for(:tdiff_each_child,tree) x.each_with_index do |xi,i| y.each_with_index do |yj,j| - c[i][j] = if tdiff_equal(xi,yj) + c[i][j] = if xi.tdiff_equal(yj) c[i-1][j-1] + 1 else if c[i][j-1] > c[i-1][j] c[i][j-1] else @@ -96,10 +93,10 @@ xi, i = next_child[x_backtrack] yj, j = next_child[y_backtrack] until (i == -1 && j == -1) - if (i != -1 && j != -1 && tdiff_equal(xi,yj)) + if (i != -1 && j != -1 && xi.tdiff_equal(yj)) changes.unshift [' ', xi] unchanged.unshift [xi, yj] xi, i = next_child[x_backtrack] yj, j = next_child[y_backtrack]