Skip to content

Instantly share code, notes, and snippets.

@heftig
Forked from chewmanfoo/simplifiable.rb
Last active December 10, 2015 20:08
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 heftig/4485827 to your computer and use it in GitHub Desktop.
Save heftig/4485827 to your computer and use it in GitHub Desktop.
def replace_line_in_file(old,new,file)
File.open(file) do |f|
File.open(file + ".new", "w") do |f2|
f.each_line do |line|
f2.puts line.gsub(old, new)
end
end
end
File.rename(file + ".new", file)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment