From: John Pritchard-williams Date: 2008-08-09T00:47:13+09:00 Subject: Re: Most compact command for associate array 'totalling'? Thanks for the replies: in fact I also prefer this one: // a = Hash.new(0) a['abc'] += 1 // As it matches exactly the behaviour of the 'awk' program and its also kinda neat looking. On the other hand this solution is also really intriguing: ( and I note the difference in behaviour as explained earlier in this post): // h=Hash.new{|h,k| h[k]=0} // So can somebody explain in English what is going on here ? This is very very Ruby to me :-) I'm guessing that we are hanging that block of the 'store' method of 'h' from now on ? I mean: so when somebody then calls something like: h.store(mykey,myvalue) it will invoke the block which will result in: h[mykey]=myvalue - but only if 'myvalue' is nil ? Is this a very specific mechanism to hashes or something really generic? Thanks again ! John -- Posted via http://www.ruby-forum.com/.