summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-07 08:34:10 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-07 08:34:10 +0000
commitba06b1a81f81e089849c7c877eba7b1d3618b126 (patch)
tree57e77c2ade50f201b4aafdc071cf86fb95eb7016 /hash.c
parentf8fc9136223c83c2791566d3efa52843f89aa127 (diff)
dynamic (nested) local variables
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index 4d170873f8..daa1e624a8 100644
--- a/hash.c
+++ b/hash.c
@@ -526,11 +526,14 @@ hash_each_key(hash)
}
static int
-each_pair_i(key, value)
+each_pair_i(key, value, rev)
VALUE key, value;
{
if (key == Qnil) return ST_CONTINUE;
- rb_yield(assoc_new(key, value));
+ if (rev)
+ rb_yield(assoc_new(value, key));
+ else
+ rb_yield(assoc_new(key, value));
return ST_CONTINUE;
}
@@ -538,7 +541,15 @@ static VALUE
hash_each_pair(hash)
VALUE hash;
{
- hash_foreach(hash, each_pair_i);
+ hash_foreach(hash, each_pair_i, 0);
+ return hash;
+}
+
+static VALUE
+hash_each_with_index(hash)
+ VALUE hash;
+{
+ hash_foreach(hash, each_pair_i, 1);
return hash;
}
@@ -1138,6 +1149,7 @@ Init_Hash()
rb_define_method(cHash,"each_value", hash_each_value, 0);
rb_define_method(cHash,"each_key", hash_each_key, 0);
rb_define_method(cHash,"each_pair", hash_each_pair, 0);
+ rb_define_method(cHash,"each_with_index", hash_each_with_index, 0);
rb_define_method(cHash,"keys", hash_keys, 0);
rb_define_method(cHash,"values", hash_values, 0);