Class: ANSI::Diff

### Home Classes Methods

### In Files

- lib/ansi/diff.rb

### Parent

Object

### Methods

- ::diff
- ::new
- #diff1
- #diff2
- #join
- #to_a
- #to_s

### Files

- COPYING.rdoc
- DEMO.rdoc
- HISTORY.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ANSI
- ANSI::BBCode
- ANSI::Chain
- ANSI::Code
- ANSI::Columns
- ANSI::Constants
- ANSI::Diff
- ANSI::HexDump
- ANSI::Logger
- ANSI::Mixin
- ANSI::ProgressBar
- ANSI::String
- ANSI::Table
- ANSI::Terminal
- Object
- String

No matching classes.

# ANSI::Diff

Diff produces colorized differences of two string or objects.

### Constants

COLORS

  Rotation of colors for diff output.

### Public Class Methods

diff(object1, object2, options={}) click to toggle source

Highlights the differnce between two strings.

This class method is equivalent to calling:

    ANSI::Diff.new(object1, object2).to_a

    # File lib/ansi/diff.rb, line 15
    def self.diff(object1, object2, options={})
      new(object1, object2, options={}).to_a
    end

new(object1, object2, options={}) click to toggle source

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.

@param [Object] object1

    First object to compare.

@param [Object] object2

    Second object to compare.

@param [Hash] options

    Options for contoller the way difference is shown. (Not yet used.)

    # File lib/ansi/diff.rb, line 33
    def initialize(object1, object2, options={})
      @object1 = convert(object1)
      @object2 = convert(object2)

      @diff1, @diff2 = diff_string(@object1, @object2)
    end

### Public Instance Methods

diff1() click to toggle source

Returns the first object's difference string.

    # File lib/ansi/diff.rb, line 41
    def diff1
      @diff1
    end

diff2() click to toggle source

Returns the second object's difference string.

    # File lib/ansi/diff.rb, line 46
    def diff2
      @diff2
    end

join(separator=$/) click to toggle source

Returns both first and second difference strings separated by a the given `separator`. The default is `$/`, the record separator.

@param [String] separator

    The string to use as the separtor between the difference strings.

@return [String] Joined difference strings.

    # File lib/ansi/diff.rb, line 67
    def join(separator=$/)
      "#{@diff1}#{separator}#{@diff2}"
    end

to_a() click to toggle source

Returns the first and second difference strings in an array.

@return [Array] Both difference strings.

    # File lib/ansi/diff.rb, line 74
    def to_a
      [diff1, diff2]
    end

to_s() click to toggle source

Returns both first and second difference strings separated by a new line character.

@todo Should we use `$/` record separator instead?

@return [String] Joined difference strings.

    # File lib/ansi/diff.rb, line 56
    def to_s
      "#{@diff1}\n#{@diff2}"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.