title: How to change the mode from read-write to read-only in a File-resource object in Ruby?
body: <p>My code needs to create a file, write to it, and then change the file-bject to read-only mode.</p>
  
  <p>What I do now, seems kindof ugly: I open the file with mode "wb", write to it, close it, then re-open it with mode "rb":</p>
  
  <pre><code>open(@cached_file_name, 'wb') { |file| file.write("foo") }    
  @cached_file = open(@cached_file_name, 'rb')
  </code></pre>
  
  <p>Is it possible to change the file from "wb" to "rb" without opening and closing it? Like: </p>
  
  <pre><code>@cached_file = open(@cached_file_name, 'wb')
  @cached_file.write("foo")
  @cached_file.mode= 'r'
  </code></pre>
  
  <p>I am not aware of such a <code>mode=</code> method though.</p>