Issue #2631 has been updated by akr.


I don't feel changing IO#reopen is great way to solve this issue.

How about spawn()?

Since Ruby 1.9, spawn provides a primitive for redirection.
It is thread safe.

Apart from that, I think $stdin, $stdout, $stderr can be thread-local
variables, though.

----------------------------------------
Feature #2631: Allow IO#reopen to take a block
https://bugs.ruby-lang.org/issues/2631#change-24703

Author: djberg96
Status: Open
Priority: Normal
Assignee: shyouhei
Category: core
Target version: 2.0.0


=begin
 Please allow IO#reopen to accept a block. This would allow users to temporarily redirect output without having to manually reset the file descriptor. For example:
 
 require 'mkmf'
  
 # stdout redirected within block only
 $stdout.reopen('/dev/null') do
   if have_header('foo.h')
     # Do stuff
   end
 end
  
 # stdout now back to its former setting
 
 I believe this is both convenient and intuitive when one considers the IO.open also takes a block.
 
 Regards,
 
 Dan
=end



-- 
http://bugs.ruby-lang.org/