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

* eval.c: unify ruby_class (for method definition) and ruby_cbase

(for constant reference).

* eval.c (rb_call0): use TMP_ALLOC() instead of allocating
  a temporary array object.

* eval.c (eval): need not to protect $SAFE value.
  [ruby-core:07177]

* error.c (Init_Exception): change NameError to direct subclass of
  Exception so that default rescue do not handle it silently.

* struct.c (rb_struct_select): update RDoc description.
  [ruby-core:7254]

* numeric.c (int_upto): return an enumerator if no block is
  attached to the method.

* numeric.c (int_downto): ditto.

* numeric.c (int_dotimes): ditto.

* enum.c (enum_first): new method Enumerable#first to take first n
  element from an enumerable.

* enum.c (enum_group_by): new method Enumerable#group_by that
  groups enumerable values according to their block values.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-02-03 09:15:42 +00:00
parent e4f1feac3e
commit 5675cdbd41
27 changed files with 657 additions and 591 deletions

View file

@ -32,18 +32,6 @@ proc_call(VALUE proc, VALUE args)
return rb_proc_call(proc, args);
}
static VALUE
method_call(VALUE method, VALUE args)
{
int argc = 0;
VALUE *argv = 0;
if (args) {
argc = RARRAY(args)->len;
argv = RARRAY(args)->ptr;
}
return rb_method_call(argc, argv, method);
}
struct enumerator {
VALUE method;
VALUE proc;
@ -168,7 +156,7 @@ enum_each_slice(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
rb_iterate(rb_each, obj, each_slice_i, (VALUE)args);
rb_block_call(obj, rb_intern("each"), 0, 0, each_slice_i, (VALUE)args);
ary = args[0];
if (RARRAY(ary)->len > 0) rb_yield(ary);
@ -235,7 +223,7 @@ enum_each_cons(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
rb_iterate(rb_each, obj, each_cons_i, (VALUE)args);
rb_block_call(obj, rb_intern("each"), 0, 0, each_cons_i, (VALUE)args);
return Qnil;
}
@ -315,14 +303,6 @@ rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
}
static VALUE
enumerator_iter(VALUE memo)
{
struct enumerator *e = (struct enumerator *)memo;
return method_call(e->method, e->args);
}
/*
* call-seq:
* enum.each {...}
@ -335,8 +315,14 @@ static VALUE
enumerator_each(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
int argc = 0;
VALUE *argv = 0;
return rb_iterate(enumerator_iter, (VALUE)e, e->iter, (VALUE)e);
if (e->args) {
argc = RARRAY(e->args)->len;
argv = RARRAY(e->args)->ptr;
}
return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
}
static VALUE
@ -360,9 +346,17 @@ enumerator_with_index(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE memo = 0;
int argc = 0;
VALUE *argv = 0;
return rb_iterate(enumerator_iter, (VALUE)e,
enumerator_with_index_i, (VALUE)&memo);
if (e->args) {
argc = RARRAY(e->args)->len;
argv = RARRAY(e->args)->ptr;
}
return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
return rb_block_call(e->method, rb_intern("call"), argc, argv,
enumerator_with_index_i, (VALUE)&memo);
}
void