Hash#default_proc= Doesn't Accept nil Argument
The initial value of a Hash's default Proc is the block passed to Hash.new or nil. Hash#default_proc= can set the default Proc to a given Proc, but can't reset it to nil. This is unsymmetrical.
The attached patch lets #default_proc= take a nil argument, and provides tests. This causes a RubySpec failure ("Hash#default_proc= raises an error if passed stuff not convertible to procs"), which I will fix if this patch is applied.
hash.c (rb_hash_set_default_proc): Accept nil, patch by Run Paint
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
#2 Updated by marcandre (Marc-Andre Lafortune) over 6 years ago
- Tracker changed from Bug to Feature
- Assignee changed from akr (Akira Tanaka) to matz (Yukihiro Matsumoto)
- Priority changed from 3 to Normal
Changing this to 'feature'.
I'm in favor of this change, with a small change to the doc. The interface should be read:
hsh.default_proc = proc_obj or nil
I think it is indeed not clear how to clear a default_proc. See:
#4 Updated by marcandre (Marc-Andre Lafortune) about 6 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100