Hash#replace should copy default as well; close #2004

This commit is contained in:
Yukihiro "Matz" Matsumoto
2014-04-04 12:14:23 +09:00
parent 9f6d69ee56
commit 59cd24d41f
3 changed files with 17 additions and 5 deletions
+3 -5
View File
@@ -376,14 +376,12 @@ mrb_hash_aget(mrb_state *mrb, mrb_value self)
static mrb_value
mrb_hash_default(mrb_state *mrb, mrb_value hash)
{
mrb_value *argv;
int argc;
mrb_value key;
mrb_bool given;
mrb_get_args(mrb, "*", &argv, &argc);
mrb_get_args(mrb, "|o?", &key, &given);
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
if (argc == 0) return mrb_nil_value();
key = argv[0];
if (!given) return mrb_nil_value();
return mrb_funcall(mrb, RHASH_PROCDEFAULT(hash), "call", 2, hash, key);
}
else {