Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rusllonrails/2653969 to your computer and use it in GitHub Desktop.
Save rusllonrails/2653969 to your computer and use it in GitHub Desktop.
Замена строк в файле виа reqexp
namespace :db do
task :parse_lines => :environment do
new_file = File.open("#{Rails.root}/lib/tasks/dummy_2.rake", 'w+')
reqexp_list = []
[/:id=>\d\d\d,/i, /:id=>\d\d,/i, /:id=>\d,/i].each do |reqexp|
reqexp_list << Regexp.new(reqexp)
end
File.open("#{Rails.root}/lib/tasks/dummy_1.rake", 'r+') do |file|
file.each_line do |line|
replace = false
reqexp_list.each do |reqexp|
if line.match(reqexp)
line = line.gsub(reqexp, '')
replace = true
end
end
new_file << line
end
new_file.close
file.close
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment