summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c26
2 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 07d8ddd8da..6023003103 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 ce1472ece0..0dd586678e 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);
}