From: Heesob Park Date: 2009-04-30T17:01:19+09:00 Subject: Re: Defining a default proc for Hash 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