Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8424975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:09:02+00:00 2026-06-10T04:09:02+00:00

I use in a genealogy program following method to add a mariage/spouse to a

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:09:03+00:00Added an answer on June 10, 2026 at 4:09 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use javascript or other method ? have any recommendation?
use strict; use warnings; my %hash = (no1=>1, no2=>2, ); my @array = %hash;
use ThreadPool.QueueUserWorkItem (WaitCallback, Object) to start a thread with my target method and data.
use Image::Imlib2; my $a = Image::Imlib2->load(/foo/file); gives me the following error: Runtime error: Image::Imlib2
Use Flex 4.5.1 and when add icons to the button is so curve effect
use POSIX; my $test = ; my $elements = scalar(@array); my $tablecount = ($elements
Use the grow() method to modify a rectangle to be twice as large. I'm
Use case : User fills out a form to add a product and register
Use Case Show a photo uploaded by the user in a square box with
use C#,want to upload excel file on google doc. bellow syntax use to upload

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.