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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:04:46+00:00 2026-05-28T00:04:46+00:00

Need to somehow match a phrase in comparison to a hash and grab the

  • 0

Need to somehow match a phrase in comparison to a hash and grab the id:

Hash:

h = [{'id' => '1', 'words' => 'blue table stand'}, {'id' => '2', 'words' => 'red table stand'}]

Word:

search = 'stand blue'

I would like to return the ids of those that has the words ‘stand’ and ‘blue’ so that I get back the id number 1. Thanks.

  • 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-28T00:04:46+00:00Added an answer on May 28, 2026 at 12:04 am

    I agree with @sawa that the data doesn’t seem to be formed in the most comfortable manner, but you never know where it came from…

    Anyway, this should work:

    search = "blue stand"
    h.select{|x| search.split.all?{|s| x["words"].split.include? s } }.map{|x| x["id"] }
    
    => ["2"]
    

    From the comments below, using the [] accessor on the string makes this shorter, and I hate scroll bars enough to update it:

    h.select{|x| search.split.all?{|s| x["words"][s] } }.map{|x| x["id"] }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to hack a 3rd party JavaScript pop-up and I need to somehow
I need to Open a process (easy) and then somehow paste data from my
I am an IT guy, and what I need to do is to somehow
PriorityBlockingQueue is unbounded, but I need to bound it somehow. What is the best
I would like to use curl, on the command line, to grab a url,
I working on a system, which need to compile and match a lot of
I'm using ruby to read a file and I need to somehow parse some
I need to find a way to find a way to find the hash
I'm new to ASP.NET MVC, but I need to perform a search for articles
I am trying to print a table in Flex 3.2 using FlexPrintJob. I need

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.