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

  • Home
  • SEARCH
  • 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 6699711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:43:40+00:00 2026-05-26T06:43:40+00:00

I have an array of hashes, this is not an active record model. This

  • 0

I have an array of hashes, this is not an active record model. This array is of objects of type Person with properties of id, name, age. I have a second array of strings, ["john", "james", "bill"].

I am attempting to remove all objects in the array of hashes except for the ones who have names in the second array, essentially performing an intersect, but I’m having quite a few problems. Any suggestions? I’m not sure if my syntax is just off or if I’m thinking about this the wrong way. Obviously I can just iterate through but this seems like its probably not the best way to handle the situation.

  • 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-26T06:43:41+00:00Added an answer on May 26, 2026 at 6:43 am

    http://www.ruby-doc.org/core-1.9.2/Array.html#method-i-select

    arr1 = [{:id => 1, :name => "John"}, {:id => 2, :name => "Doe"}];
    arr2 = ["Doe"];
    
    intersect = arr1.select {|o| arr2.include? o[:name]} # you can also use select!
    p intersect # outputs [{:name=>"Doe", :id=>2}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of hashes. Each entry looks like this: - !map:Hashie::Mash name:
I have an array of hashes that looks like this: [{:head_count=>150.5, :group=>NW, :estimated_ship_date=>201105, :yard=>wcc},
I have an array of hashes that looks like this: user_array = [<#Hashie::Mash id=1
This is the first time I have manipulated hashes and arrays in this way
I have an array of hashes, and I want the unique values out of
I have a Ruby method that searches an array of hashes and returns a
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have an array of hashes, many of which have shared keys. I would
I have a category collection and each category has a array of hashes containing

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.