summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-01 05:22:15 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-12-01 05:22:15 +0000
commitd09047674dadf481cc68c1bf01ce1bd5c611d1a3 (patch)
treec9258153cf7fb7cd58c6f3312b559f6d668cefd4
parent61d7065be290eb93fc8e1e560cf250c02315108e (diff)
downloadruby-d09047674dadf481cc68c1bf01ce1bd5c611d1a3.tar.gz
ruby-d09047674dadf481cc68c1bf01ce1bd5c611d1a3.tar.xz
ruby-d09047674dadf481cc68c1bf01ce1bd5c611d1a3.zip
* io.c (rb_f_open): use to_open for every non-string object. path
object may use method_missing. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14064 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--io.c26
2 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 07d8ddd8d..602300310 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,11 @@ Sat Dec 1 13:24:47 2007 Koichi Sasada <ko1@atdot.net>
* 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>
* insns.def (concatarray, splatarray): use to_a instead of
diff --git a/io.c b/io.c
index ce1472ece..0dd586678 100644
--- a/io.c
+++ b/io.c
@@ -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);
}