From: naruse@... Date: 2017-06-22T08:35:20+00:00 Subject: [ruby-core:81740] [Ruby trunk Feature#2631][Open] Allow IO#reopen to take a block Issue #2631 has been updated by naruse (Yui NARUSE). Status changed from Closed to Open ������������������ wrote: > Applied in changeset trunk|r59142. > > ---------- > Allow IO#reopen to take a block > > * io.c (rb_io_reopen): take a block and ensure the IO closed > [Feature #2631] > > * test/ruby/test_io.rb: add a test > > * NEWS: add an entry for this change This patch looks doesn't recover the original $stdout. Morever though this was approved before, this is strange because block changes global state. If this is introduced in 7 years ago, it may be acceptable. But in this 201x year Ruby really should support multithread unsafe code? People who want to write unsafe code should explicitly write code like following. ``` require 'mkmf' # stdout redirected within block only orig_stdout = $stdout open(IO:NULL, 'w') do |f| $stdout = f if have_header('foo.h') # Do stuff end ensure $stdout = orig_stdout end ``` ---------------------------------------- Feature #2631: Allow IO#reopen to take a block https://bugs.ruby-lang.org/issues/2631#change-65442 * Author: djberg96 (Daniel Berger) * Status: Open * Priority: Normal * Assignee: shyouhei (Shyouhei Urabe) * Target version: next minor ---------------------------------------- =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 -- https://bugs.ruby-lang.org/ Unsubscribe: