From a68451d61015e094d804d286027ac22d443aab62 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 30 Oct 2007 01:06:10 +0000 Subject: * 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 --- ChangeLog | 8 ++++++++ enum.c | 38 ++++++++++++++++++++++++++++++++++++++ enumerator.c | 5 +---- version.h | 6 +++--- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 116ff36cec..6866ecb0ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Oct 30 10:03:43 2007 Yukihiro Matsumoto + + * 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 * parse.y (bvar): block-local variable can shadow outer variable. diff --git a/enum.c b/enum.c index 82a64fe0a3..2c4a4e947b 100644 --- a/enum.c +++ b/enum.c @@ -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. + * n 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); diff --git a/enumerator.c b/enumerator.c index 5ce861d9bb..487ce51bb9 100644 --- a/enumerator.c +++ b/enumerator.c @@ -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 */ diff --git a/version.h b/version.h index 7b6d17053c..ff5a51016f 100644 --- a/version.h +++ b/version.h @@ -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[]; -- cgit v1.2.3