mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
io.c: recurse for the argument
* io.c (rb_io_puts): recurse for the argument itself, not converted array elements. [ruby-core:42444] [Bug #5986] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
af4ceeff10
commit
01eb117b01
3 changed files with 22 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Sat Dec 1 19:24:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* io.c (rb_io_puts): recurse for the argument itself, not converted
|
||||
array elements. [ruby-core:42444] [Bug #5986]
|
||||
|
||||
Sat Dec 1 19:01:36 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* marshal.c (w_object, r_object0): call private marshal methods.
|
||||
|
|
10
io.c
10
io.c
|
@ -6660,13 +6660,15 @@ io_puts_ary(VALUE ary, VALUE out, int recur)
|
|||
if (recur) {
|
||||
tmp = rb_str_new2("[...]");
|
||||
rb_io_puts(1, &tmp, out);
|
||||
return Qnil;
|
||||
return Qtrue;
|
||||
}
|
||||
ary = rb_check_array_type(ary);
|
||||
if (NIL_P(ary)) return Qfalse;
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
tmp = RARRAY_PTR(ary)[i];
|
||||
rb_io_puts(1, &tmp, out);
|
||||
}
|
||||
return Qnil;
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -6705,9 +6707,7 @@ rb_io_puts(int argc, VALUE *argv, VALUE out)
|
|||
line = argv[i];
|
||||
goto string;
|
||||
}
|
||||
line = rb_check_array_type(argv[i]);
|
||||
if (!NIL_P(line)) {
|
||||
rb_exec_recursive(io_puts_ary, line, out);
|
||||
if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
|
||||
continue;
|
||||
}
|
||||
line = rb_obj_as_string(argv[i]);
|
||||
|
|
|
@ -2583,5 +2583,17 @@ End
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_puts_recursive_ary
|
||||
bug5986 = '[ruby-core:42444]'
|
||||
c = Class.new {
|
||||
def to_ary
|
||||
[self]
|
||||
end
|
||||
}
|
||||
s = StringIO.new
|
||||
s.puts(c.new)
|
||||
assert_equal("[...]\n", s.string, bug5986)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue