Skip to content

Instantly share code, notes, and snippets.

@vivien
Created August 10, 2011 23:00
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 vivien/1138510 to your computer and use it in GitHub Desktop.
Save vivien/1138510 to your computer and use it in GitHub Desktop.
Insert text after a given line of a file
def insert_into file, lineno, text
new_text = File.readlines(file).insert(lineno, text + "\n").join
File.open(file, 'w') { |f| f.write new_text }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment