brew/Library/Homebrew/utils/inreplace.rb
Jason Whittle 2c23e71be3 let inreplace take a symbol
As discussed in https://github.com/mxcl/homebrew/pull/21936

Closes Homebrew/homebrew#21942.

Signed-off-by: Adam Vandenberg <flangy@gmail.com>
2013-08-17 07:40:27 -07:00

26 lines
617 B
Ruby

module Utils
module Inreplace
def inreplace paths, before=nil, after=nil
Array(paths).each do |path|
f = File.open(path, 'r')
s = f.read
if before.nil? && after.nil?
s.extend(StringInreplaceExtension)
yield s
else
after = after.to_s if Symbol === after
sub = s.gsub!(before, after)
if sub.nil?
opoo "inreplace in '#{path}' failed"
puts "Expected replacement of '#{before}' with '#{after}'"
end
end
f.reopen(path, 'w').write(s)
f.close
end
end
end
end