summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-09 10:56:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-09 10:56:24 +0000
commitb814252d728cb08f159da1777feca4f8e9362327 (patch)
treede6617897dbf6bce78045e3fa2ea84ea2422f166 /hash.c
parent1bbcd202e4dab0894bc5ed68ce4ea84dc916980f (diff)
1.1b7 pre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@67 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/hash.c b/hash.c
index ba531f4..9208857 100644
--- a/hash.c
+++ b/hash.c
@@ -179,7 +179,7 @@ hash_foreach(hash, func, farg)
arg.hash = hash;
arg.func = func;
arg.arg = farg;
- return rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, (VALUE)hash);
+ return rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
}
static VALUE
@@ -307,7 +307,7 @@ hash_rehash(hash)
RHASH(hash)->tbl = tbl;
if (RHASH(hash)->iter_lev > 0) RHASH(hash)->status |= HASH_REHASHED;
- return (VALUE)hash;
+ return hash;
}
VALUE
@@ -405,7 +405,7 @@ hash_delete_if(hash)
hash_modify(hash);
hash_foreach(hash, delete_if_i, 0);
- return (VALUE)hash;
+ return hash;
}
static int
@@ -422,7 +422,7 @@ hash_clear(hash)
hash_modify(hash);
st_foreach(RHASH(hash)->tbl, clear_i);
- return (VALUE)hash;
+ return hash;
}
VALUE
@@ -441,6 +441,25 @@ hash_aset(hash, key, val)
return val;
}
+static int
+replace_i(key, val, hash)
+ VALUE key, val, hash;
+{
+ hash_aset(hash, key, val);
+ return ST_CONTINUE;
+}
+
+static VALUE
+hash_replace(hash, hash2)
+ VALUE hash, hash2;
+{
+ Check_Type(hash2, T_HASH);
+ hash_clear(hash);
+ st_foreach(RHASH(hash2)->tbl, replace_i, hash);
+
+ return hash;
+}
+
static VALUE
hash_length(hash)
VALUE hash;
@@ -471,7 +490,7 @@ hash_each_value(hash)
VALUE hash;
{
hash_foreach(hash, each_value_i);
- return (VALUE)hash;
+ return hash;
}
static int
@@ -488,7 +507,7 @@ hash_each_key(hash)
VALUE hash;
{
hash_foreach(hash, each_key_i);
- return (VALUE)hash;
+ return hash;
}
static int
@@ -505,7 +524,7 @@ hash_each_pair(hash)
VALUE hash;
{
hash_foreach(hash, each_pair_i);
- return (VALUE)hash;
+ return hash;
}
static int
@@ -1095,6 +1114,7 @@ Init_Hash()
rb_define_method(cHash,"[]", hash_aref, 1);
rb_define_method(cHash,"[]=", hash_aset, 2);
rb_define_method(cHash,"indexes", hash_indexes, -1);
+ rb_define_method(cHash,"indices", hash_indexes, -1);
rb_define_method(cHash,"length", hash_length, 0);
rb_define_alias(cHash, "size", "length");
rb_define_method(cHash,"empty?", hash_empty_p, 0);
@@ -1113,6 +1133,7 @@ Init_Hash()
rb_define_method(cHash,"clear", hash_clear, 0);
rb_define_method(cHash,"invert", hash_invert, 0);
rb_define_method(cHash,"update", hash_update, 1);
+ rb_define_method(cHash,"replace", hash_replace, 1);
rb_define_method(cHash,"include?", hash_has_key, 1);
rb_define_method(cHash,"has_key?", hash_has_key, 1);
@@ -1135,6 +1156,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"rehash", env_none, 0);
rb_define_singleton_method(envtbl,"to_a", env_to_a, 0);
rb_define_singleton_method(envtbl,"indexes", env_indexes, -1);
+ rb_define_singleton_method(envtbl,"indices", env_indexes, -1);
rb_define_singleton_method(envtbl,"length", env_size, 0);
rb_define_singleton_method(envtbl,"empty?", env_empty_p, 0);
rb_define_singleton_method(envtbl,"keys", env_keys, 0);