Hi, Am Montag, 10. Aug 2009, 15:32:44 +0900 schrieb David A. Black: > On Mon, 10 Aug 2009, Bertram Scharpf wrote: > >> Am Montag, 10. Aug 2009, 08:17:42 +0900 schrieb 7stud --: >>> Bertram Scharpf wrote: >>>> h = Hash.new { |h,k| h[k] = 0 } >>> >>> h = Hash.new { |h,k| h[k] = 0 } >>> >>> is equivalent to: >>> >>> h = Hash.new(0) >> >> Arrgh. Of course. > > Actually they're not equivalent. > >>> h = Hash.new(0) > => {} >>> h[1] > => 0 >>> h > => {} >>> h = Hash.new {|h,k| h[k] = 0 } > => {} >>> h[1] > => 0 >>> h > => {1=>0} Arrgh. Of course. I remind that my code called Hash#[] just in h[e] += 1 and therefore it is even more efficient to use the default value solution. Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de