Skip to content

Instantly share code, notes, and snippets.

@Olefine
Created July 20, 2013 09:30
Show Gist options
  • Select an option

  • Save Olefine/6044447 to your computer and use it in GitHub Desktop.

Select an option

Save Olefine/6044447 to your computer and use it in GitHub Desktop.
append something into middle of file
def append_config_to_file
tempfile = File.open("file.rb", 'w')
f = File.new("config/application.rb")
f.each do |line|
tempfile << line
if line.match(/class Application/)
tempfile << " config.autoload_paths += %W(\#{config.root}/searches)\n"
end
end
f.close
tempfile.close
FileUtils.mv("file.rb", "config/application.rb")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment