summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/array.c b/array.c
index 3ba450cbe91..d88a9fcc3fd 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;