ruby-changes:2302
From: ko1@a...
Date: 30 Oct 2007 10:06:55 +0900
Subject: [ruby-changes:2302] matz - Ruby:r13793 (trunk): * enum.c (enum_butfirst): add a new method to iterates over
matz 2007-10-30 10:06:10 +0900 (Tue, 30 Oct 2007)
New Revision: 13793
Modified files:
trunk/ChangeLog
trunk/enum.c
trunk/enumerator.c
trunk/version.h
Log:
* 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.
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/version.h?r1=13793&r2=13792
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=13793&r2=13792
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/enum.c?r1=13793&r2=13792
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/enumerator.c?r1=13793&r2=13792
Index: ChangeLog
===================================================================
--- ChangeLog (revision 13792)
+++ ChangeLog (revision 13793)
@@ -1,3 +1,11 @@
+Tue Oct 30 10:03:43 2007 Yukihiro Matsumoto <matz@r...>
+
+ * 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@r...>
* parse.y (bvar): block-local variable can shadow outer variable.
Index: enumerator.c
===================================================================
--- enumerator.c (revision 13792)
+++ enumerator.c (revision 13793)
@@ -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 @@
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 */
Index: enum.c
===================================================================
--- enum.c (revision 13792)
+++ enum.c (revision 13793)
@@ -1331,6 +1331,43 @@
}
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)
{
volatile VALUE result = memo->u1.value;
@@ -1606,6 +1643,7 @@
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);
Index: version.h
===================================================================
--- version.h (revision 13792)
+++ version.h (revision 13793)
@@ -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[];
--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml