diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-15 08:07:41 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-15 08:07:41 +0000 |
commit | a973f9698fe0045e3fd494ebb9f85c2f686a9ed9 (patch) | |
tree | 355cad957cc31192647488758ba7c050cd21d840 /enum.c | |
parent | ed8fb0876d09647ac1baf64b3f67cdcb135c7413 (diff) | |
download | ruby-a973f9698fe0045e3fd494ebb9f85c2f686a9ed9.tar.gz |
* enum.c (enum_all): now works without block.
* enum.c (enum_any): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 32 |
1 files changed, 28 insertions, 4 deletions
@@ -287,7 +287,7 @@ enum_sort_by(obj) } static VALUE -all_i(i, memo) +all_iter_i(i, memo) VALUE i; NODE *memo; { @@ -299,6 +299,18 @@ all_i(i, memo) } static VALUE +all_i(i, memo) + VALUE i; + NODE *memo; +{ + if (!RTEST(i)) { + memo->u1.value = Qfalse; + rb_iter_break(); + } + return Qnil; +} + +static VALUE enum_all(obj) VALUE obj; { @@ -306,14 +318,14 @@ enum_all(obj) NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0); memo->u1.value = Qtrue; - rb_iterate(rb_each, obj, all_i, (VALUE)memo); + rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)memo); result = memo->u1.value; rb_gc_force_recycle((VALUE)memo); return result; } static VALUE -any_i(i, memo) +any_iter_i(i, memo) VALUE i; NODE *memo; { @@ -325,6 +337,18 @@ any_i(i, memo) } static VALUE +any_i(i, memo) + VALUE i; + NODE *memo; +{ + if (RTEST(i)) { + memo->u1.value = Qtrue; + rb_iter_break(); + } + return Qnil; +} + +static VALUE enum_any(obj) VALUE obj; { @@ -332,7 +356,7 @@ enum_any(obj) NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0); memo->u1.value = Qfalse; - rb_iterate(rb_each, obj, any_i, (VALUE)memo); + rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)memo); result = memo->u1.value; rb_gc_force_recycle((VALUE)memo); return result; |