summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/enum.c b/enum.c
index a49e4b0b74..d378e48967 100644
--- a/enum.c
+++ b/enum.c
@@ -515,7 +515,14 @@ enum_flat_map(VALUE obj)
static VALUE
enum_to_a(int argc, VALUE *argv, VALUE obj)
{
- VALUE ary = rb_ary_new();
+ VALUE ary, size = rb_check_funcall(obj, id_size, 0, 0);
+
+ if (size == Qundef) {
+ ary = rb_ary_new();
+ }
+ else {
+ ary = rb_ary_new2(NUM2LONG(size));
+ }
rb_block_call(obj, id_each, argc, argv, collect_all, ary);
OBJ_INFECT(ary, obj);