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

* io.c (argf_seek_m): wrong calling sequence of rb_io_seek().

* parse.y (cond0): no special treatment of string literal in
  condition.

* math.c: add acos, asin, atan, conh, sinh, tanh and hypot to Math.

* configure.in: check hypot availablility.

* missing/hypot.c: public domain rewrite of hypot.

* parse.y (warn_unless_e_option): warning condition was wrong.

* parse.y (warning_unless_e_option): ditto.

* enum.c (enum_all): new method 'all?', which returns true if
  block returns true for all elements.

* enum.c (enum_any): new method 'any?', which returns true if
  block retruns true for any of elements.

* marshal.c (marshal_load): do not give warning unless explicitly
  set to verbose.

* eval.c (rb_exit): give string value "exit" to SystemExit.

* ruby.c (proc_options): -v should not print version if
  proc_options called via moreswitches().

* parse.y (stmt): while/until modifier must work for empty body.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-03-13 05:45:13 +00:00
parent 8fc5876485
commit e502549be1
20 changed files with 266 additions and 71 deletions

58
enum.c
View file

@ -87,10 +87,10 @@ enum_find(argc, argv, obj)
rb_gc_force_recycle((VALUE)memo);
return memo->u1.value;
}
rb_gc_force_recycle((VALUE)memo);
if (!NIL_P(if_none)) {
rb_eval_cmd(if_none, rb_ary_new2(0));
}
rb_gc_force_recycle((VALUE)memo);
return Qnil;
}
@ -147,7 +147,7 @@ collect_i(i, tmp)
}
static VALUE
enum_all(i, ary)
collect_all(i, ary)
VALUE i, ary;
{
rb_ary_push(ary, i);
@ -161,7 +161,7 @@ enum_to_a(obj)
VALUE ary;
ary = rb_ary_new();
rb_iterate(rb_each, obj, enum_all, ary);
rb_iterate(rb_each, obj, collect_all, ary);
return ary;
}
@ -173,7 +173,7 @@ enum_collect(obj)
VALUE tmp;
tmp = rb_ary_new();
rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : enum_all, tmp);
rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : collect_all, tmp);
return tmp;
}
@ -203,6 +203,54 @@ enum_sort(obj)
return rb_ary_sort(enum_to_a(obj));
}
static VALUE
all_i(i, memo)
VALUE i;
NODE *memo;
{
if (!RTEST(rb_yield(i))) {
memo->u1.value = Qfalse;
rb_iter_break();
}
return Qnil;
}
static VALUE
enum_all(obj)
VALUE 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_gc_force_recycle((VALUE)memo);
return memo->u1.value;
}
static VALUE
any_i(i, memo)
VALUE i;
NODE *memo;
{
if (RTEST(rb_yield(i))) {
memo->u1.value = Qtrue;
rb_iter_break();
}
return Qnil;
}
static VALUE
enum_any(obj)
VALUE 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_gc_force_recycle((VALUE)memo);
return memo->u1.value;
}
static VALUE
min_i(i, memo)
VALUE i;
@ -358,6 +406,8 @@ Init_Enumerable()
rb_define_method(rb_mEnumerable,"collect", enum_collect, 0);
rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
rb_define_method(rb_mEnumerable,"inject", enum_inject, 1);
rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
rb_define_method(rb_mEnumerable,"min", enum_min, 0);
rb_define_method(rb_mEnumerable,"max", enum_max, 0);
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);