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 772781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:51:26+00:00 2026-05-14T18:51:26+00:00

I have four arrays that are coming in from the client. Let’s say that

  • 0

I have four arrays that are coming in from the client. Let’s say that there is an array of names, birth dates, favorite color and location. The idea is I want a hash later where each name will have a hash with respective attributes:

Example date coming from the client:

[name0, name1, name2, name3]
[loc0, loc1]
[favcololor0, favcolor1]
[bd0, bd1, bd2, bd3, bd4, bd5]

Output I’d like to achieve:

name0 => { location => loc0, favcolor => favcolor0, bd => bd0 }
name1 => { location => loc1, favcolor => favcolor1, bd => bd1 }
name2 => { location => nil, favcolor => nil, bd => bd2 }
name3 => { location => nil, favcolor => nil, bd => bd3 }

I want to have an array at the end of the day where I can iterate and work on each particular person hash.

There need not be an equivalent number of values in each array. Meaning, names are required.. and I might receive 5 of them, but I only might receive 3 birth dates, 2 favorite colors and 1 location. Every missing value will result in a nil.

How does one make that kind of data structure with Ruby 1.9?

  • 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-05-14T18:51:27+00:00Added an answer on May 14, 2026 at 6:51 pm

    I would probably do it like this

    # assuming names, fav_colors, birth_dates, and locations are your arrays
    
    name_collection = {}
    
    names.zip(birth_dates, fav_colors, locations) do |name, birth_date, fav_color, location|
      name_collection[name] = { :birth_date => birth_date,
                                :fav_color => fav_color,
                                :location => location }
    end
    
    # usage
    puts name_collection['jack'][:fav_color] # => 'blue'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that requires the following. Four arrays will be declared in
How can I store arrays in single array? e.g. I have four different arrays,
I have four arrays: $qtys = $_POST['qty']; $colours = $_POST['colour']; $sizes = $_POST['size']; $names
Let's say I have 4 arrays: [1,3,54,4] [54,2,3,9] [3,2,9,54] [54,8,4,3] I need to get
Let's say I have an array of floating point numbers, in sorted (let's say
Let's say I have two arrays in my javascript: var content = [string1, string2,
I will be short, what i have is array=( one.a two.b tree.c four.b five_b_abc)
i have four tables user-question contains two columns: questionID, userID, the questions that the
i have four imageviews in a linear layout in such a manner that only
In my C# code, I have constructed four arrays of data: double[] values; DateTime[]

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.