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 | |
parent | ed8fb0876d09647ac1baf64b3f67cdcb135c7413 (diff) |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | enum.c | 32 | ||||
-rw-r--r-- | eval.c | 1 |
3 files changed, 35 insertions, 4 deletions
@@ -12,6 +12,12 @@ Tue Jan 14 21:47:56 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net> the suffix specifiched. [ruby-dev:18702] http://moonrock.jp/~don/d/200211.html#d08_t1 +Tue Jan 14 18:36:41 2003 Yukihiro Matsumoto <matz@ruby-lang.org> + + * enum.c (enum_all): now works without block. + + * enum.c (enum_any): ditto. + Tue Jan 14 01:21:32 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net> * io.c (next_argv): not always set binmode. @@ -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; @@ -5613,6 +5613,7 @@ rb_f_require(obj, fname) SafeStringValue(fname); ext = strrchr(RSTRING(fname)->ptr, '.'); + if (ext && strchr(ext, '/')) ext = 0; if (ext) { if (strcmp(".rb", ext) == 0) { feature = rb_str_dup(fname); |