文字列置換

# repase_string.rb FIND_STRING REPLASE_STRING **/*.apt

require 'fileutils'

def replase_string(find_string, replase_string, files)
  puts "find_string = #{find_string}, replase_string=#{replase_string}"
  puts "files = #{files.inspect}"

  files.each{|file|
    puts "copying #{file} to #{file}.org"
    FileUtils.copy("#{file}",  "#{file}.org")

    result = ""
    open(file){ |infile| 
      infile.each{ |line| 
        result << line.gsub(find_string, replase_string)
      }
    }
    open("#{file}","w" ) { |writer|
      writer.puts result
      puts "write #{file}"
    }
  }
end

find_string =  ARGV.shift
replase_string =  ARGV.shift

replase_string(find_string, replase_string, ARGV)