title: Remove trailing white-spaces from each line in a file
body: <p>I am using ruby and I want to remove trailing white-spaces at the end of each line in a file.</p>
  
  <p>One way to do this,
  iterate line by line and save it in another file and then replace new file with the old one.</p>
  
  <pre><code>  temp_file = Tempfile.new("temp")
    f.each_line do |line|
      new_line = line.rstrip
      temp_file.puts  new_line
    end
  </code></pre>
  
  <p>but this is not what I want.
  I want to use the method which we generally use in C,C++ without using any temporary file that is, move file pointer to the front of line by new line and overwrite it.</p>
  
  <p>How can we do this in ruby ??</p>