diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-01 05:22:15 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-01 05:22:15 +0000 |
commit | 70e28cf1ebb0edc674aa60556ed125f7f32e1984 (patch) | |
tree | c9258153cf7fb7cd58c6f3312b559f6d668cefd4 /io.c | |
parent | 2bbffcd6a401f047beda6ec4aadacc2c899afec6 (diff) | |
download | ruby-70e28cf1ebb0edc674aa60556ed125f7f32e1984.tar.gz |
* io.c (rb_f_open): use to_open for every non-string object. path
object may use method_missing.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -3782,20 +3782,20 @@ rb_io_s_sysopen(int argc, VALUE *argv) static VALUE rb_f_open(int argc, VALUE *argv) { - if (argc >= 1) { - ID to_open = rb_intern("to_open"); + ID to_open; + int redirect = Qfalse; + if (argc >= 1) { + to_open = rb_intern("to_open"); if (rb_respond_to(argv[0], to_open)) { - 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; + redirect = Qtrue; } else { VALUE tmp = rb_check_string_type(argv[0]); - if (!NIL_P(tmp)) { + if (NIL_P(tmp)) { + redirect = Qtrue; + } + else { char *str = StringValuePtr(tmp); if (str && str[0] == '|') { argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1); @@ -3805,6 +3805,14 @@ rb_f_open(int argc, VALUE *argv) } } } + if (redirect) { + 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; + } return rb_io_s_open(argc, argv, rb_cFile); } |