diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-21 09:13:10 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-21 09:13:10 +0000 |
commit | c74466e1c9c428cc7066d89e31da396b021c6fb9 (patch) | |
tree | 061b2d92ff153ba66d7705952de72ae8a4f3fe14 /enum.c | |
parent | 5e479b4e092fa8bf169757d32264f9f9cec15c68 (diff) |
merges r23622 from trunk into ruby_1_9_1.
--
* enum.c (first_i): Enumerator#first should consume only what is
needed. a patch from Marc-Andre Lafortune. [ruby-core:23661]
* enum.c (enum_first): call to_int once for an argument. based on
a patch from Marc-Andre Lafortune.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@23776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -616,14 +616,14 @@ first_i(VALUE i, VALUE *ary, int argc, VALUE *argv) rb_iter_break(); } else { - long n = NUM2LONG(ary[0]); + long n = ary[0]; + rb_ary_push(ary[1], i); + n--; if (n <= 0) { rb_iter_break(); } - rb_ary_push(ary[1], i); - n--; - ary[0] = INT2NUM(n); + ary[0] = n; } return Qnil; } @@ -648,9 +648,13 @@ enum_first(int argc, VALUE *argv, VALUE obj) ary[0] = ary[1] = Qnil; } else { + long len; + rb_scan_args(argc, argv, "01", &n); - ary[0] = n; - ary[1] = rb_ary_new2(NUM2LONG(n)); + len = NUM2LONG(n); + if (len == 0) return rb_ary_new2(0); + ary[0] = len; + ary[1] = rb_ary_new2(len); } rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary); |