Wow I like that. This is what I end up doing:

ha = {}
(ha[any_key] ||= []) << anything

J

On 07/02/2009, at 4:09 AM, Robert Klemme wrote:

>
> Hi there,
>
> we frequently do
>
> ha = Hash.new {|h,k| h[k] = []}
>
> so we can later do
>
> ha[any_key] << anything
>
> Since the idiom is so common, what does everybody think of putting  
> it into the standard library:
>
> def Hash.with_arrays
>  new {|h,k| h[k] = []}
> end
>
> While we're at it, we might as well add
>
> def Hash.with_hashes
>  new {|h,k| h[k] = Hash.new(&h.default_proc)}
> end
>
> Kind regards
>
> 	robert
>