1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2003-01-15 08:07:41 +00:00
parent ed8fb0876d
commit a973f9698f
3 changed files with 35 additions and 4 deletions

View file

@ -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.

32
enum.c
View file

@ -287,7 +287,7 @@ enum_sort_by(obj)
}
static VALUE
all_i(i, memo)
all_iter_i(i, memo)
VALUE i;
NODE *memo;
{
@ -298,6 +298,18 @@ all_i(i, memo)
return Qnil;
}
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,18 +318,30 @@ 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_iter_i(i, memo)
VALUE i;
NODE *memo;
{
if (RTEST(rb_yield(i))) {
memo->u1.value = Qtrue;
rb_iter_break();
}
return Qnil;
}
static VALUE
any_i(i, memo)
VALUE i;
NODE *memo;
{
if (RTEST(rb_yield(i))) {
if (RTEST(i)) {
memo->u1.value = Qtrue;
rb_iter_break();
}
@ -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;

1
eval.c
View file

@ -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);