Class: SubDiff::Differ

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sub_diff/differ.rb

Instance Method Summary collapse

Constructor Details

#initialize(builder, type) ⇒ Differ

Returns a new instance of Differ.



7
8
9
10
# File 'lib/sub_diff/differ.rb', line 7

def initialize(builder, type)
  @builder = builder
  @type = type
end

Instance Method Details

#each_diff(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/sub_diff/differ.rb', line 12

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

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