summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-25 08:22:11 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-01-25 08:22:11 +0000
commitf547c1150cf0cb9fe2477e6aeb4ff7b724fc44c7 (patch)
treebdf1c6377a12f1405ac48b2819ac59fbeb4c12a5 /hash.c
parenteb9708f38671aa6446a89acc755f3341f5cb59b6 (diff)
* class.c (rb_include_module): detect cyclic module inclusion.
* eval.c (rb_thread_cleanup): need not to free thread stacks at process termination. * array.c (rb_ary_fetch): use the block to get the default value if the block is given. * eval.c (rb_thread_schedule): should check time only if BOTH WAIT_SELECT and WAIT_TIME. * eval.c (umethod_bind): should update rklass field. * hash.c (rb_hash_update): if a block is given, yields [key, value1, value2] to the block to resolve conflict. * string.c (rb_str_split_m): no need to consider KANJI characters, if the length of separator is 1 (byte). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2015 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index 6c4f8cb..0f91bc6 100644
--- a/hash.c
+++ b/hash.c
@@ -889,12 +889,30 @@ rb_hash_update_i(key, value, hash)
return ST_CONTINUE;
}
+static int
+rb_hash_update_block_i(key, value, hash)
+ VALUE key, value;
+ VALUE hash;
+{
+ if (key == Qundef) return ST_CONTINUE;
+ if (rb_hash_has_key(hash, key)) {
+ value = rb_yield(rb_ary_new3(3, key, rb_hash_aref(hash, key), value));
+ }
+ rb_hash_aset(hash, key, value);
+ return ST_CONTINUE;
+}
+
static VALUE
rb_hash_update(hash1, hash2)
VALUE hash1, hash2;
{
hash2 = to_hash(hash2);
- st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1);
+ if (rb_block_given_p()) {
+ st_foreach(RHASH(hash2)->tbl, rb_hash_update_block_i, hash1);
+ }
+ else {
+ st_foreach(RHASH(hash2)->tbl, rb_hash_update_i, hash1);
+ }
return hash1;
}
@@ -985,7 +1003,7 @@ env_fetch(argc, argv)
if (!env) {
if (rb_block_given_p()) {
if (argc > 1) {
- rb_raise(rb_eArgError, "wrong number of arguments", argc);
+ rb_raise(rb_eArgError, "wrong number of arguments");
}
return rb_yield(key);
}