diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-28 09:20:03 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-28 09:20:03 +0000 |
commit | 1011775a395e901aa897301dc5fecb9270fc1646 (patch) | |
tree | b05880a19cf90ba3fe5790f9cd9e5d4b55059013 /array.c | |
parent | a40ca8c047d8c174d1757dcbc82ec16185144717 (diff) |
introduces r21693 again and merges r21713
* array.c (take_items), enum.c (enum_zip): tries to convert to
array first. [ruby-core:21442]
--
* array.c (take_items): to_ary() raises ArgumentError if cannot to
convert to Array. [ruby-dev:37797]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21814 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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 = rb_check_array_type(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; |