http://www.un.org/Depts/DGACM/index_french.htm
Sets the default value, the value returned for a key that does not
exist in the hash. It is not possible to set the default to a Proc
that will be executed on each key lookup.
因此,你可以这样做:
irb(main):037:0> h = Hash.new { |hash, key| hash[key] = [] }
=> {}
irb(main):038:0> h[1] << "2"
=> ["2"]
irb(main):039:0> h
=> {1=>["2"]}
也可使用default_proc:
irb(main):047:0> h = {}
irb(main):047:0> h.default_proc = proc {|hash, key| hash[key] = []}
=> #<Proc:0x23939a0@(irb):47>
irb(main):049:0> h[1] << 3
=> [3]
irb(main):050:0> h
=> {1=>[3]}