diff options
author | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-27 07:48:11 +0000 |
---|---|---|
committer | (no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-27 07:48:11 +0000 |
commit | 7425d4f6ef047dd274cbea8115955462d5449330 (patch) | |
tree | 575dcd5c8f6df0908e4198376441d4257dcde75d /enum.c | |
parent | fd1d8cdc09ed86e4a0812120a17ff0d7b04adcaf (diff) |
This commit was manufactured by cvs2svn to create tag 'r1_1b9'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/r1_1b9@100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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"); |