1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?xml version="1.0" ?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>doc/diff.rd</title>
</head>
<body>
<h1><a name="label:0" id="label:0">Diff</a></h1><!-- RDLabel: "Diff" -->
<p><code>diff.rb</code> - computes the differences between two arrays or
strings. Copyright (C) 2001-2002 Lars Christensen.</p>
<h2><a name="label:1" id="label:1">Synopsis</a></h2><!-- RDLabel: "Synopsis" -->
<pre>diff = Diff.diff(a, b)
a.diff(b)
b = a.patch(diff)</pre>
<h2><a name="label:2" id="label:2">Module Diff</a></h2><!-- RDLabel: "Module Diff" -->
<h3><a name="label:3" id="label:3">Module Methods</a></h3><!-- RDLabel: "Module Methods" -->
<dl>
<dt><a name="label:4" id="label:4"><code>Diff.diff(<var>a</var>, <var>b</var>, &<var>block</var>)</code></a></dt><!-- RDLabel: "Diff.diff" -->
<dd>
<p>Creates a different set which represents the differences between
<var>a</var> and <var>b</var>. <var>a</var> and <var>b</var> can be either be arrays
with elements of any type, strings, or object of any class that
include module <var>Diffable</var></p>
<p>If a block is not given, the default is to compact the
difference set elements into an array of element of the type
<code>[action,position,elements]</code>. If action is :+, the array
represent elements which is in b but not a which are inserted at
<var>position</var>. If action is :-, the array represents elements
which are in a at <var>position</var> but has been removed from b. If
the original data was arrays, <var>elements</var> will be an array of
elements. If the original data was Strings, then <var>elements</var>
will be a string.c</p>
<p>If a block is given, it will be passed each of the element in
the difference set. Each time it is called, three arguments are
passed: action, position and element. Action is either :+ or :-
for add or remove element, respectively. If the action is :+,
position will denote the position to add element in the
destination set, given all previous before this are changed. If
the action is :-, position will denote the position to delete
elements from the original set.</p></dd>
</dl>
<h2><a name="label:5" id="label:5">Module Diffable</a></h2><!-- RDLabel: "Module Diffable" -->
<p>The <var>Diffable</var> module can be included into classes that you want
to compute difference sets for Diffable is included into String and
Array when <code>diff.rb</code> is <code>require</code>'d.</p>
<p>Classes including Diffable should implement <code>[]</code> to get element at
integer indices, <code><<</code> and <code>push</code> to append elements to the
object and <code>ClassName#new</code> should accept 0 arguments to create a
new empty object. Finally, the class must implement the length method
which should return the number of element in the array.</p>
<h3><a name="label:6" id="label:6">Instance Methods</a></h3><!-- RDLabel: "Instance Methods" -->
<dl>
<dt><a name="label:7" id="label:7"><code>Diffable#diff(<var>b</var>, &<var>block</var>)</code></a></dt><!-- RDLabel: "Diffable#diff" -->
<dd>
<p>Convinience method which calls Diff.diff(self, b, &block).</p></dd>
<dt><a name="label:8" id="label:8"><code>Diffable#patch(<var>diff</var>)</code></a></dt><!-- RDLabel: "Diffable#patch" -->
<dd>
<p>Applies the differences from <var>diff</var> to the object <var>obj</var>
and return the result. <var>obj</var> is not changed. <var>obj</var> and
can be either an array or a string, but must match the object
from which the <var>diff</var> was created.</p></dd>
</dl>
</body>
</html>
|