title: How can I convert an IO object to a string in Ruby?
body: <p>I'm working with an IO object (some <code>STDOUT</code> output text), and I'm trying to convert it to a string so that I can do some text processing. I would like to do something like this:</p>
  
  <pre><code>my_io_object = $stdout
  #=&gt; #&lt;IO:&lt;STDOUT&gt;&gt;
  
  my_io_object.puts('hi')  #note: I know how to make 'hi' into a string, but this is a simplified example
  #=&gt;hi
  
  my_io_object.to_s
  </code></pre>
  
  <p>I have tried a few things and gotten a few errors:</p>
  
  <pre><code>my_io_object.read 
  #=&gt; IOError: not opened for reading
  
  my_io_object.open
  #=&gt; NoMethodError: private method `open' called for #&lt;IO:&lt;STDOUT&gt;&gt;
  
  IO.read(my_io_object)
  #=&gt; TypeError: can't convert IO into String
  </code></pre>
  
  <p>I've read through the IO class methods, and I can't figure out how to manipulate the data in that object. Any suggestions?</p>