From cab67c31977e8c5b466f38dcb8800cbe6b32b60e Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 19 Jan 2009 21:47:48 +0000 Subject: [PATCH] * array.c (take_items), enum.c (enum_zip): tries to convert to array first. [ruby-core:21442] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ array.c | 4 +++- enum.c | 8 ++++++-- test/ruby/test_array.rb | 5 +++++ test/ruby/test_enum.rb | 5 +++++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 173e08482b..3d4347d059 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jan 20 06:48:56 2009 Nobuyoshi Nakada + + * array.c (take_items), enum.c (enum_zip): tries to convert to + array first. [ruby-core:21442] + Tue Jan 20 03:50:37 2009 NARUSE, Yui * ext/nkf/nkf-utf8/nkf.c: Update nkf to 2.0.9. diff --git a/array.c b/array.c index 3ba450cbe9..d88a9fcc3f 100644 --- a/array.c +++ b/array.c @@ -2209,9 +2209,11 @@ take_i(VALUE val, VALUE *args, int argc, VALUE *argv) static VALUE take_items(VALUE obj, long n) { - VALUE result = rb_ary_new2(n); + VALUE result = to_ary(obj); VALUE args[2]; + if (!NIL_P(result)) return rb_ary_subseq(result, 0, n); + result = rb_ary_new2(n); args[0] = result; args[1] = (VALUE)n; rb_block_call(obj, rb_intern("each"), 0, 0, take_i, (VALUE)args); return result; diff --git a/enum.c b/enum.c index 0bb8b6453c..8c4b5b93e0 100644 --- a/enum.c +++ b/enum.c @@ -1558,13 +1558,17 @@ enum_zip(int argc, VALUE *argv, VALUE obj) ID conv; NODE *memo; VALUE result = Qnil; + VALUE args = rb_ary_new4(argc, argv); int allary = Qtrue; + argv = RARRAY_PTR(args); for (i=0; i