Srijayanth Sridhar
4/30/2009 9:50:00 AM
[Note: parts of this message were removed to make it a legal post.]
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 <phasis@gmail.com> wrote:
> 2009/4/30 Srijayanth Sridhar <srijayanth@gmail.com>:
> > 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
>
>