2006/3/15, Pete Goodeve <pete / jwgibbs.cchem.berkeley.edu>:
>
> I've hit what is either an egregious bug in ruby (1.8.4) or some subtlety
> that I haven't grasped.  [Most likely the latter... (:-)]
>
> Briefly I had two arrays of symbol strings of which I wanted to find
> which symbols occurred in both arrays, so I thought I'd use a hash with
> the key being the symbol and the value a two element array that would
> be used to flag which set(s) the symbol was found in.  The following
> is a simplified (and 'instrumented') version of what I was trying to
> do:
>
> listA=["line1","line2","line3"]
> listB=["line5","line3","line4"]
> table={}

Here's the problem:

> table.default=[0,0]


What you are looking for is:

table = Hash.new { |h, k|  h[k] = [0, 0] }

otherwise you are always pointing to _the same_ object