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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:47:25+00:00 2026-06-18T04:47:25+00:00

In order to compute the cartesian product in Ruby, one can use Array#product ,

  • 0

In order to compute the cartesian product in Ruby, one can use Array#product, how is the syntax if I have an array of arrays and want to compute the product?

[[1,2],[3,4],[5,6]] => [[1,3,5], [2,3,5], ...]

I am not sure, because in the Ruby documentation the product method is defined with an arbitrary number of arguments, so simply passing my arrays of arrays as an argument, like that:

[].product(as) => [

does not suffice. How can I solve this?

  • 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-06-18T04:47:26+00:00Added an answer on June 18, 2026 at 4:47 am

    The method takes multiple arguments, but not an array containing arguments. So you have to use it in this way:

    [1,2].product [3,4], [5,6]
    

    If as is your array of arrays, you will have to “splat” it like this:

    as[0].product(*as[1..-1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How fast can one compute CRC32 for hashing very large amounts of data? (order
in order to avoid copy/paste, i can use a unique view for different actions,
Can somebody please demonstrate for me a more efficient Cartesian product algorithm than the
How do I compute order statistics by group in R. I want to aggregate
I can successfully compute the 200 day moving average for one ticker using a
Imagine I want to, say, compute the first one million terms of the Fibonacci
Is there a better way to compute Cartesian product. Since Cartesian product is a
I have a system of (first order) ODEs with fairly expensive to compute derivatives.
I have a program that needs to repeatedly compute the approximate percentile (order statistic)
I want to compute an md5 hash not of a string, but of an

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.