Class: ANSI::Diff
- Inherits:
-
Object
- Object
- ANSI::Diff
- Defined in:
- lib/ansi/diff.rb
Overview
Diff produces colorized differences of two string or objects.
Class Method Summary collapse
-
.diff(object1, object2, options = {}) ⇒ Object
Highlights the differnce between two strings.
Instance Method Summary collapse
-
#diff1 ⇒ Object
Returns the first object's difference string.
-
#diff2 ⇒ Object
Returns the second object's difference string.
-
#initialize(object1, object2, options = {}) ⇒ Diff
constructor
Setup new Diff object.
-
#join(separator = $/) ⇒ String
Returns both first and second difference strings separated by a the given
separator. -
#to_a ⇒ Array
Returns the first and second difference strings in an array.
-
#to_s ⇒ String
Returns both first and second difference strings separated by a new line character.
Constructor Details
#initialize(object1, object2, options = {}) ⇒ Diff
Setup new Diff object. If the objects given are not Strings
and do not have #to_str defined to coerce them to such, then
their #inspect methods are used to convert them to strings
for comparison.
33 34 35 36 37 38 |
# File 'lib/ansi/diff.rb', line 33 def initialize(object1, object2, ={}) @object1 = convert(object1) @object2 = convert(object2) @diff1, @diff2 = diff_string(@object1, @object2) end |
Class Method Details
Instance Method Details
#diff1 ⇒ Object
Returns the first object's difference string.
41 42 43 |
# File 'lib/ansi/diff.rb', line 41 def diff1 @diff1 end |
#diff2 ⇒ Object
Returns the second object's difference string.
46 47 48 |
# File 'lib/ansi/diff.rb', line 46 def diff2 @diff2 end |
#join(separator = $/) ⇒ String
Returns both first and second difference strings separated by a
the given separator. The default is $/, the record separator.
67 68 69 |
# File 'lib/ansi/diff.rb', line 67 def join(separator=$/) "#{@diff1}#{separator}#{@diff2}" end |
#to_a ⇒ Array
Returns the first and second difference strings in an array.
74 75 76 |
# File 'lib/ansi/diff.rb', line 74 def to_a [diff1, diff2] end |
#to_s ⇒ String
Should we use $/ record separator instead?
Returns both first and second difference strings separated by a new line character.
56 57 58 |
# File 'lib/ansi/diff.rb', line 56 def to_s "#{@diff1}\n#{@diff2}" end |