summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-10 08:44:05 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-10 08:44:05 +0000
commit36f3603cae6536e571220721e916b8d284cf0675 (patch)
treeeb9605811483000f6980263aa163b4f627ab1c3f /enum.c
parentfd1d8cdc09ed86e4a0812120a17ff0d7b04adcaf (diff)
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
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c22
1 files changed, 21 insertions, 1 deletions
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");