C
Chris Conley
Hello,
I'm trying to insert new text into the middle of a file with the
following:
file = File.open("file.rb", "r+")
file.each { |line|
if line.match(/line text/)
file.puts("hello")
end
}
This works fine except that it overwrites the existing 5 characters to
replace with "hello". Is there a way to insert a new line with new
text without overwriting any existing data?
Thanks!
Chris
I'm trying to insert new text into the middle of a file with the
following:
file = File.open("file.rb", "r+")
file.each { |line|
if line.match(/line text/)
file.puts("hello")
end
}
This works fine except that it overwrites the existing 5 characters to
replace with "hello". Is there a way to insert a new line with new
text without overwriting any existing data?
Thanks!
Chris