From: Bertram Scharpf Date: 2007-08-26T09:31:21+09:00 Subject: Re: class X < Hash ... how do I do X.new { |hash, key| ...} ? Hi, Am Sonntag, 26. Aug 2007, 09:06:24 +0900 schrieb Larry Fast: > I created a child class of Hash and would like to internalize the > equivalent of Hash.new {|hash,key| } The following code failed: > > class X < Hash > def initialize > super { |hash,key| ... } > end > end > > Any suggestions? Any error messages? I pipe the following code from here in the editor into Ruby: -------------------------------- class H < Hash def initialize super { |h,k| h[k] = Time.now } end end h = H.new puts h[:x] sleep 1 puts h[:y] puts h[:x] -------------------------------- Sun Aug 26 02:30:35 +0200 2007 Sun Aug 26 02:30:36 +0200 2007 Sun Aug 26 02:30:35 +0200 2007 -------------------------------- Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de