Class: SubDiff::Differ

Inherits:
Struct
  • Object
show all
Defined in:
lib/sub_diff/differ.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#diff_collectionObject

Returns the value of attribute diff_collection

Returns:

  • (Object)

    the current value of diff_collection



2
3
4
# File 'lib/sub_diff/differ.rb', line 2

def diff_collection
  @diff_collection
end

#diff_methodObject

Returns the value of attribute diff_method

Returns:

  • (Object)

    the current value of diff_method



2
3
4
# File 'lib/sub_diff/differ.rb', line 2

def diff_method
  @diff_method
end

Instance Method Details

#diff(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/sub_diff/differ.rb', line 3

def diff(*args)
  # Ruby 1.8.7 does not support additional args after * (splat)
  block = args.pop

  differ.call(args.first) do |match|
    diff = { :match => match, :prefix => $`, :suffix => $' }
    diff[:replacement] = match.sub(*args, &block)
    yield(diff_collection, diff)
  end

  diff_collection
end