Feature #4234

Hash#default_proc= Doesn't Accept nil Argument

Added by Run Paint Run Run about 4 years ago. Updated almost 3 years ago.

[ruby-core:34108]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune

Description

=begin
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.
=end

hash-default-proc.patch Magnifier (973 Bytes) Run Paint Run Run, 01/06/2011 01:11 AM

Associated revisions

Revision 35268
Added by Marc-Andre Lafortune almost 3 years ago

  • hash.c (rb_hash_set_default_proc): Accept nil, patch by Run Paint
    [Feature #4234]

  • test/ruby/test_hash.rb: test for above.

Revision 35268
Added by Marc-Andre Lafortune almost 3 years ago

  • hash.c (rb_hash_set_default_proc): Accept nil, patch by Run Paint
    [Feature #4234]

  • test/ruby/test_hash.rb: test for above.

History

#1 Updated by Yui NARUSE over 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Akira Tanaka

#2 Updated by Marc-Andre Lafortune almost 3 years ago

  • Tracker changed from Bug to Feature
  • Assignee changed from Akira Tanaka to Yukihiro Matsumoto
  • Priority changed from Low 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:
http://stackoverflow.com/questions/3818623/marshal-ruby-hash-with-default-proc-remove-the-default-proc

Thoughts?

#3 Updated by Yukihiro Matsumoto almost 3 years ago

  • Assignee changed from Yukihiro Matsumoto to Marc-Andre Lafortune

Agreed. Marc, could you check this patch in (with document update)?

Matz.

#4 Updated by Marc-Andre Lafortune almost 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r35268.
Run Paint, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • hash.c (rb_hash_set_default_proc): Accept nil, patch by Run Paint
    [Feature #4234]

  • test/ruby/test_hash.rb: test for above.

Also available in: Atom PDF