summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-22 06:50:32 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-06-22 06:50:32 +0000
commitf1b7003f35cae684cceeab710a5769458dfe7310 (patch)
tree3e9967a80821a0c38f456b1b6d803bc2a172a97e /io.c
parent2a46ba9423f44d2d673525eaa7ea48d12679e279 (diff)
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/io.c b/io.c
index 3482602326..8b0064b2dc 100644
--- a/io.c
+++ b/io.c
@@ -7058,6 +7058,10 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
}
}
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, file, io_close, file);
+ }
+
return file;
}