alan,

> I was wondering about this behavior:
>
> md = Hash.new { |h,k| h[h] = 0; 3 }
> p md[1]   # => 3
> p md[1]   # => 0
>
> I understand that the first "p md[1]" is returning
> the result of the block; is that intentional?

    Yes.  A clearer example:

md = Hash.new { 3 }
md[1] = 1
p md[1]    => 1
p md[2]    => 3
p md       => {1=>1}

    Remember, the main point of the block is to generate a default value for
nonexistent keys.  The autovivication trick is merely an extension of this
functionality.

    I hope this helps.

    - Warren Brown