summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/io.c b/io.c
index 9765fa7566..f2f46a64fc 100644
--- a/io.c
+++ b/io.c
@@ -3071,7 +3071,11 @@ rb_f_open(argc, argv)
ID to_open = rb_intern("to_open");
if (rb_respond_to(argv[0], to_open)) {
- return rb_funcall2(argv[0], to_open, argc-1, argv+1);
+ VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1);
+ if (rb_block_given_p()) {
+ return rb_ensure(rb_yield, io, io_close, io);
+ }
+ return io;
}
else {
VALUE tmp = rb_check_string_type(argv[0]);