Bug #2212
closedUsing a Lambda with Inappropriate Arity for Hash#default_proc=
Description
=begin
If the default_proc of a Hash is a lambda whose arity != 2, key lookups raise an ArgumentError. To understand this exception the user must know that the hash has a default proc, lambdas perform strict argument checking, and that the lambda is passed two arguments.
Instead, perhaps Hash#default_proc and Hash.new could raise a helpful error message if they're passed a lambda with an arity other than 2. This localises the exception to where the default_proc is set, as opposed to where an element is referenced, and better explains the problem.
h={}
=> {}
h.default_proc=->{ true }
=> #<Proc:0x9eaaea8@(irb):12 (lambda)>
h[:key]
ArgumentError: wrong number of arguments (2 for 0)
from (irb):13:inyield' from (irb):13:in
default'
from (irb):13
from /usr/local/bin/irb:12:in `'
=end