From: Srijayanth Sridhar Date: 2009-04-30T18:49:59+09:00 Subject: Re: Defining a default proc for Hash --000e0cd59d0c67caa90468c29e15 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks, That's twice in two days that merge has come up wrt Hash. Jayanth On Thu, Apr 30, 2009 at 1:31 PM, Heesob Park wrote: > 2009/4/30 Srijayanth Sridhar : > > Yes, I did. All that tells me is that it isn't possible to set a default > > proc using default or any other calls. Which is why I asked, if there is > any > > *other* way to do it. If not, it simply can't be done. Of course, it > would > > also be nice if someone could explain the rationale for not wanting to > alter > > the default proc once it has been defined. > > > You can do it like this: > > class Hash > def default_proc=(blk) > self.replace(Hash.new(&blk).merge(self)) > end > end > > h = {1=>2,3=>4} > p h.default_proc > h.default_proc = proc {|h,k| h[k]=3 } > p h.default_proc > > Regards, > > Park Heesob > > --000e0cd59d0c67caa90468c29e15--