diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-09 04:07:53 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-04-09 04:07:53 +0000 |
commit | 6b18a8c2e9540f67de5887f899d73e100c3ce13f (patch) | |
tree | 5037c18957dd3217a1efd6e392ef957e4b2c5f99 /hash.c | |
parent | 6cb7ac7e155b15d542297eac32b2cd03efca8b60 (diff) | |
download | ruby-6b18a8c2e9540f67de5887f899d73e100c3ce13f.tar.gz |
* 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.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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, |