From: Gary Wright Date: 2007-11-06T04:35:28+09:00 Subject: Re: x=[]; x[:bla][:some_key] does not work? On Nov 5, 2007, at 5:27 AM, David A. Black wrote: > My favorite is: > > class NonexistentKeyError < StandardError > end > > hash = Hash.new {|h,k| raise NonexistentKeyError, "No such key: # > {k}" } An alternate solution: a = Hash.new { |h,k| h.fetch k } David's solution is nice because the message includes the key. Maybe Ruby's IndexError message should report the unknown key. Gary Wright