I am accessing a file, and before I append to it, I want to delete the last line from the file. Is there any efficient way of doing this in Ruby?
This is what I am using to access the file:
file = File.new("imcs2.xml", "a")
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you want to remove the entire last line of the file, you can use this method which locates the start of the last line and begins writing from there: