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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:09:25+00:00 2026-05-15T17:09:25+00:00

How do I create an exclusion for a array map in Ruby. Here’s what

  • 0

How do I create an exclusion for a array map in Ruby.
Here’s what I want to achieve,

a = [1,2,3,4]
b = [5,6,7,8]
a.map.each do |x|
  b.map.each do |y|
    if !(x == 1 && y == 7)
      puts "#{x} and #{y}"
    elsif !(x == 4 && y == 8)
      puts "#{x} and #{y}"
    end
  end
end

1 and 5
1 and 6
1 and 7 # still here
1 and 8
2 and 5
2 and 6
2 and 7
2 and 8
3 and 5
3 and 6
3 and 7
3 and 8
4 and 5
4 and 6
4 and 7
4 and 8 # still here

However, it doesn’t work, how do I add an exception to these values being processed by map? Also if it’s possible to use inject/reject/filter function with the same goal.

  • 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-15T17:09:26+00:00Added an answer on May 15, 2026 at 5:09 pm

    To explain why 1 and 7 is still printing, step through the logic:

    1. if !(x == 1 && y == 7)
      • x == 1 is true and y == 7 is true, therefore !(true && true) is false, this is skipped.
    2. elsif !(x == 4 && y == 8)
      • the if was skipped, so the elsif is evaluated. x == 4 is false (since x is still 1) and y == 8 is false (since y is still 7). Therefore, !(false && false) is true, and the puts is reached.

    Because x can never be both 1 and 4 at the same time and y can never be 7 and 8 at the same time, either your if statement or your elsif statement will always succeed, and since both branches print, the values will be always printed, no matter what x and y are.

    As other answers said, you need to combine your clauses.

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

Sidebar

Related Questions

I want to create a vector from each element of the sequences returned below
I want to create some distributed mutual exclusion using a database table. It would
CREATE TABLE #Report( Cell int, CellValue double) Error here DECLARE @Report TABLE ( Cell
I want to ensure users can't create usernames that clash with my existing routes.
in order to test another class, I want to create a stub for an
I'm creating a Q&A application in CakePHP, and I want to exclude my associations
i'm loading several sound files, and want to error check each load. however, instead
CREATE TABLE `tbl_atn` ( `atn_id` int(15) NOT NULL AUTO_INCREMENT, `eng_id` int(15) DEFAULT NULL, `visit`
CREATE OR REPLACE FUNCTION layer2layerAttribute RETURN VARCHAR2 AS /** * This function properly joins
CREATE TABLE #TEMPTABLE ( requestTime datetime2, NoOfSessions integer ) INSERT INTO #TEMPTABLE select convert(nvarchar(16),

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.