--0-991652494-12316016973839 Content-Type: text/plain; charset=us-ascii Thanks, David. I think I understand it now. ________________________________ From: David A. Black <dblack / rubypal.com> To: ruby-talk ML <ruby-talk / ruby-lang.org> Sent: Saturday, January 10, 2009 9:53:49 AM Subject: Re: Default values of hashes Hi -- On Wed, 7 Jan 2009, Glenn wrote: > Thanks for the tips. I learned a lot from all of the suggestions. > > Not sure, though, if I understand this line: > > hash[1][2][3] ash.new(0) > > Is that a valid line on its own. If so, it does not seem to work for me. I get the following error: > > undefined method `[] for 0 Here's how to use it: >> hproc ambda {|h,k| h[k] ash.new(&hproc) } #<Proc:0x00248420@(irb):14> >> hash ash.new(&hproc) {} >> hash[1][2][3] ash.new(0) {} >> hash[1][2][3]["x"] + 0 10 >> hash[1][2][3] {"x"0} David -- David A. Black / Ruby Power and Light, LLC Ruby/Rails consulting & training: http://www.rubypal.com Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2) http://www.wishsight.com Independent, social wishlist management! --0-991652494-12316016973839--