1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2007-12-01 05:22:15 +00:00
parent 2bbffcd6a4
commit 70e28cf1eb
2 changed files with 22 additions and 9 deletions

View file

@ -13,6 +13,11 @@ Sat Dec 1 13:24:47 2007 Koichi Sasada <ko1@atdot.net>
* bootstraptest/test_block.rb: ditto. * bootstraptest/test_block.rb: ditto.
Sat Dec 1 10:45:56 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (rb_f_open): use to_open for every non-string object. path
object may use method_missing.
Sat Dec 1 09:44:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org> Sat Dec 1 09:44:32 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* insns.def (concatarray, splatarray): use to_a instead of * insns.def (concatarray, splatarray): use to_a instead of

26
io.c
View file

@ -3782,20 +3782,20 @@ rb_io_s_sysopen(int argc, VALUE *argv)
static VALUE static VALUE
rb_f_open(int argc, VALUE *argv) rb_f_open(int argc, VALUE *argv)
{ {
ID to_open;
int redirect = Qfalse;
if (argc >= 1) { if (argc >= 1) {
ID to_open = rb_intern("to_open"); to_open = rb_intern("to_open");
if (rb_respond_to(argv[0], to_open)) { if (rb_respond_to(argv[0], to_open)) {
VALUE io = rb_funcall2(argv[0], to_open, argc-1, argv+1); redirect = Qtrue;
if (rb_block_given_p()) {
return rb_ensure(rb_yield, io, io_close, io);
}
return io;
} }
else { else {
VALUE tmp = rb_check_string_type(argv[0]); VALUE tmp = rb_check_string_type(argv[0]);
if (!NIL_P(tmp)) { if (NIL_P(tmp)) {
redirect = Qtrue;
}
else {
char *str = StringValuePtr(tmp); char *str = StringValuePtr(tmp);
if (str && str[0] == '|') { if (str && str[0] == '|') {
argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1); 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); return rb_io_s_open(argc, argv, rb_cFile);
} }