Q:

use of index with a hash instead of an array

I use in a genealogy program following method to add a mariage/spouse to a Person.
@mariages is an array of arrays.
def add_spouse(spouse, mariage_date = nil, divorce_date = nil)
  @mariages.push([spouse, mariage_date, divorce_date]) unless @mariages.index{|(a, b, c)| a == spouse && b == mariage_date} 
  spouse.mariages.push(self) unless spouse.mariages.index{|(a, b, c)| a == self && b == mariage_date} 
end

With the unless @mariages.index{|(a, b, c)| a == spouse && b == mariage_date} i check if the mariage is not allready in the array.
Now i want to keep my mariages in an array of hashes like this
def add_spouse(spouse, mariage_date = nil, divorce_date = nil)
    @mariages.push({:spouse => spouse, :mariage_date => mariage_date, :divorce_date => divorce_date}) unless ...
    spouse.mariages.push({:spouse => self, :mariage_date => mariage_date, :divorce_date => divorce_date}) unless ... 
end

Can someone help me adapt the unless part to do the check if the hash is not allready presant in the array ?

A:

In the block that goes into index the element getting iterated over is a hash so you should use 
.. unless @mariages.index{|h| h[:spouse] == spouse && h[:mariage_date] == mariage_date}

and 
.. unless spouse.mariages.index{|h| h[:spouse] == self && h[:mariage_date] == mariage_date} 

PS: mariage is misspelled. It should be marriage. 

