From: "David A. Black" Date: 2007-11-05T19:27:19+09:00 Subject: Re: x=[]; x[:bla][:some_key] does not work? Hi -- On Mon, 5 Nov 2007, Bob Hutchison wrote: > I've been using Ruby for years and I'm still startled by what you can do when > passing blocks to initializers. A few weeks ago I stumbled on this: > > Hash.new{ | h, k | h[k] = Array.new } > > which is just a hash of arrays, completely trivial really, but I'd never > thought of it before, and now I'm using it all over the place. My favorite is: class NonexistentKeyError < StandardError end hash = Hash.new {|h,k| raise NonexistentKeyError, "No such key: #{k}" } :-) David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!