Created
August 10, 2011 23:00
-
-
Save vivien/1138510 to your computer and use it in GitHub Desktop.
Insert text after a given line of a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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