From 36f3603cae6536e571220721e916b8d284cf0675 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Tue, 10 Feb 1998 08:44:05 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'v1_1b7'. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_1b7@70 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enum.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'enum.c') diff --git a/enum.c b/enum.c index d8e2fcdc8b..3b804fae48 100644 --- a/enum.c +++ b/enum.c @@ -6,7 +6,7 @@ $Date$ created at: Fri Oct 1 15:15:19 JST 1993 - Copyright (C) 1993-1996 Yukihiro Matsumoto + Copyright (C) 1993-1998 Yukihiro Matsumoto ************************************************/ @@ -356,6 +356,25 @@ enum_length(obj) return INT2FIX(length); } +each_with_index_i(val, indexp) + VALUE val; + int *indexp; +{ + rb_yield(assoc_new(val, INT2FIX(*indexp))); + (*indexp)++; + return Qnil; +} + +VALUE +enum_each_with_index(obj) + VALUE obj; +{ + int index = 0; + + rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&index); + return Qnil; +} + void Init_Enumerable() { @@ -376,6 +395,7 @@ Init_Enumerable() rb_define_method(mEnumerable,"include?", enum_member, 1); rb_define_method(mEnumerable,"length", enum_length, 0); rb_define_method(mEnumerable,"size", enum_length, 0); + rb_define_method(mEnumerable,"each_with_index", enum_each_with_index, 0); id_eqq = rb_intern("==="); id_each = rb_intern("each"); -- cgit v1.2.3