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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:41:37+00:00 2026-05-24T17:41:37+00:00

I am working on Rails 3.0. I have a two dimensional array. The two

  • 0

I am working on Rails 3.0. I have a two dimensional array. The two dimensional array consists of user data and a boolean value.

For example: [ [user1,true], [user2,true], [user3,false] ]

It looks something like this:

[
    [#<User id: 1, email: "abc@abc.com", username: "abc">, true],
    [#<User id: 2, email: "ijk@ijk.com", username: "ijk">, true],
    [#<User id: 3, email: "xyz@xyz.com", username: "xyz">, false],
]

I want to find/extract records conditionally; say finding an entire row where User id=2, it should return only the second row i.e. [#<User id: 2, email: "ijk@ijk.com", username: "ijk">, true]

Is there anyway to loop through such arrays? How can it be achieved?

  • 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-24T17:41:38+00:00Added an answer on May 24, 2026 at 5:41 pm
    my_array.select{ |user, flag| user.id == 2}
    

    all users with true flag:

    my_array.select{ |user, flag| flag }
    

    or false:

    my_array.select{ |user, flag| !flag }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Rails application where I have some a set of two
I have two fields, 'from_date' and 'to_date' on my rails form. When a user
I'm new to Rails and am working with the collection_select method. I have two
I working in Rails 3 Activerecord. I have two models City and Shipment and
I am working on a rails application (I have some experience with rails). But,
I am thinking of working on a Rails application that uses PostgreSQL. I have
Hi Currently i am working on a rails project . where i have to
Background Currently, I am working on a Rails application. I have different products that
I have a fantasy football league rails app that was working last year and
I'm working with an older version of Rails and ActiveRecord that does not have

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.