summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-09 04:07:53 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-09 04:07:53 +0000
commit6b18a8c2e9540f67de5887f899d73e100c3ce13f (patch)
tree5037c18957dd3217a1efd6e392ef957e4b2c5f99 /hash.c
parent6cb7ac7e155b15d542297eac32b2cd03efca8b60 (diff)
* hash.c (rb_hash_set_default_proc): Accept nil, patch by Run Paint
[Feature #4234] * test/ruby/test_hash.rb: test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/hash.c b/hash.c
index 4764bdd6b2..9d14d3f73f 100644
--- a/hash.c
+++ b/hash.c
@@ -689,9 +689,9 @@ rb_hash_default_proc(VALUE hash)
/*
* call-seq:
- * hsh.default_proc = proc_obj -> proc_obj
+ * hsh.default_proc = proc_obj or nil
*
- * Sets the default proc to be executed on each key lookup.
+ * Sets the default proc to be executed on each failed key lookup.
*
* h.default_proc = proc do |hash, key|
* hash[key] = key + key
@@ -706,6 +706,11 @@ rb_hash_set_default_proc(VALUE hash, VALUE proc)
VALUE b;
rb_hash_modify_check(hash);
+ if (NIL_P(proc)) {
+ FL_UNSET(hash, HASH_PROC_DEFAULT);
+ RHASH_IFNONE(hash) = proc;
+ return proc;
+ }
b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
if (NIL_P(b) || !rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError,