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

* enum.c (enum_butfirst): add a new method to iterates over

elements but first n.  RDoc need to be updated.

* enumerator.c (Init_Enumerator): remove unnecessary symbol
  initialization.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13793 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2007-10-30 01:06:10 +00:00
parent f3cbb20b22
commit a68451d610
4 changed files with 50 additions and 7 deletions

View file

@ -1,3 +1,11 @@
Tue Oct 30 10:03:43 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* enum.c (enum_butfirst): add a new method to iterates over
elements but first n. RDoc need to be updated.
* enumerator.c (Init_Enumerator): remove unnecessary symbol
initialization.
Mon Oct 29 18:42:17 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (bvar): block-local variable can shadow outer variable.

38
enum.c
View file

@ -1330,6 +1330,43 @@ enum_each_with_index(int argc, VALUE *argv, VALUE obj)
return obj;
}
static VALUE
butfirst_i(VALUE val, long *n)
{
if (*n > 0) {
(*n)--;
return Qnil;
}
else {
return rb_yield(val);
}
}
/*
* call-seq:
* e.butfirst {|x| ... }
* e.butfirst(n) {|x| ... }
*
* Iterates the given block for each elements except for first n elements.
* <i>n</i> defaults to 1.
*
*/
static VALUE
enum_butfirst(int argc, VALUE *argv, VALUE obj)
{
VALUE tmp;
long n;
rb_scan_args(argc, argv, "01", &tmp);
RETURN_ENUMERATOR(obj, argc, argv);
if (argc == 0) n = 1;
else n = NUM2LONG(tmp);
rb_block_call(obj, id_each, 0, 0, butfirst_i, (VALUE)&n);
return obj;
}
static VALUE
zip_i(VALUE val, NODE *memo)
{
@ -1606,6 +1643,7 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, -1);
rb_define_method(rb_mEnumerable, "butfirst", enum_butfirst, -1);
rb_define_method(rb_mEnumerable, "zip", enum_zip, -1);
rb_define_method(rb_mEnumerable, "take", enum_take, -1);
rb_define_method(rb_mEnumerable, "drop", enum_drop, -1);

View file

@ -22,7 +22,7 @@
* object.
*/
static VALUE rb_cEnumerator;
static VALUE sym_each, sym_each_with_index, sym_each_slice, sym_each_cons, sym_call;
static VALUE sym_each, sym_call;
VALUE rb_eStopIteration;
@ -471,9 +471,6 @@ Init_Enumerator(void)
rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError);
sym_each = ID2SYM(rb_intern("each"));
sym_each_with_index = ID2SYM(rb_intern("each_with_index"));
sym_each_slice = ID2SYM(rb_intern("each_slice"));
sym_each_cons = ID2SYM(rb_intern("each_cons"));
sym_call = ID2SYM(rb_intern("call"));
rb_provide("enumerator.so"); /* for backward compatibility */

View file

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-10-29"
#define RUBY_RELEASE_DATE "2007-10-30"
#define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20071029
#define RUBY_RELEASE_CODE 20071030
#define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 10
#define RUBY_RELEASE_DAY 29
#define RUBY_RELEASE_DAY 30
#ifdef RUBY_EXTERN
RUBY_EXTERN const char ruby_version[];