title: Replace line in text file with a new line
body: <p>I want to replace a line in a file with a new line, example being:</p>
  
  <p>File:</p>
  
  <pre><code>test
  test
  test
  testing
  test
  </code></pre>
  
  <p>Source:</p>
  
  <pre><code>def remove_line(line)
    if line == line
      #remove line including whitespace
      File.open('test.txt', 'a+') { |s| s.puts('removed successfully') }
    end
  end
  </code></pre>
  
  <p>So the expected output of this would be something like this:</p>
  
  <pre><code>remove_line('testing')
  test
  test
  test
  removed successfully
  test
  </code></pre>
  
  <p>Now I've done some research and have only been able to find adding a blank line, I guess I could run through it and remove all blank lines and just append to the file, but there has to be an easier way to replace a line with another string?</p>