Brian Fundakowski Feldman <green / FreeBSD.org> writes:

> Hash.new may take an argument that specifies the default value for
> hash members.  To do it with empty arrays, for example:

>...

> Hope it helps!

'fraid not.

Currently the default parameter is evaluated just once, so all entries 
will default to having the same empty array.

  h = Hash.new(Array.new)
  h['cat'] << 'hello'
  h['dog'] << 'goodbye'
  puts h['cat'].inspect  #=> ["hello", "goodbye"]


However, there's some talk of a new syntax:

 h = Hash.new { stuff }

Where the block will be evaluated to create missing elements.


Regards


Dave