From: Srijayanth Sridhar Date: 2009-04-30T16:34:44+09:00 Subject: Re: Defining a default proc for Hash --000e0cd56b088513260468c0bae8 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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. Thank you, Jayanth On Thu, Apr 30, 2009 at 12:58 PM, 7stud -- wrote: > Srijayanth Sridhar wrote: > > Hello, > > > > Is there a way to redefine or newly define a default proc for Hash way > > after > > it has been constructed and populated with elements? > > > > There seems to be a #default= but no #default_proc= > > > > Did you read this? > > ---------------------------------------------------------- Hash#default= > hsh.default = obj => hsh > ------------------------------------------------------------------------ > .... > > It is not possible to set the a default to a > +Proc+ that will be executed on each key lookup. > > ... > > # This doesn't do what you might hope... > h.default = proc do |hash, key| > hash[key] = key + key > end > h[2] #=> # > h["cat"] #=> # > > > > > -- > Posted via http://www.ruby-forum.com/. > > --000e0cd56b088513260468c0bae8--