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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:27:54+00:00 2026-06-11T14:27:54+00:00

Lets say I have an array of Match objects, each belonging to a round

  • 0

Lets say I have an array of Match objects, each belonging to a round in a round robin tournament structure…

Matches

Round     | Registrant_ID     |Registrant_ID_2    |Winner_id
1         |    1              |    2              |   2 
1         |    3              |    4              |   4
1         |    5              |    6              |   5
1         |    7              |    8              |   8
2         |    1              |    4              |   1
2         |    3              |    6              |   3
2         |    5              |    8              |   5
2         |    7              |    2              |   2
3         |    1              |    6              |   1
...

What I wish to do is group all of the matches by Round and loop through that round and list the matches.

The desired output would be something like…

 <h1>Round 1</h1>    
 <table>
 <thead>
  <tr>
   <th>Player 1</th>
   <th>Player 2</th>
   <th>Winner</th>
  </tr>
 </thead>
 <tbody>
  <tr>
    <td>1</td>
    <td>2</td>
    <td>2</td>
  </tr>
  <tr>
    <td>3</td>
    <td>4</td>
    <td>4</td>
  </tr>
  <tr>
    <td>5</td>
    <td>6</td>
    <td>5</td>
  </tr>
  <tr>
    <td>7</td>
    <td>8</td>
    <td>8</td>
  </tr>
 </tbody>
</table>

The problem I’m facing is that I don’t know how to loop through the match records by their round attribute. I’m not sure if something like in_groups_of can be used because the number of players that participate in a round will vary, it won’t always be 8 as seen here.

Here is my code thus far which simply loops through all records and creates a table for every match(I’m looking for tables for individual rounds):

- @matches.each do |match|
  %h1= "Round #{match.round}"
  %table.table.table-bordered
    %thead
      %tr
        %th.span4 Player 1
        %th.span4 Player 2
        %th.span4 Winner
    %tbody
      %tr
        %td= match.register.user.username
        %td= match.register_2.user.username
        %td= match.winner.user.username unless match.winner.nil?

Here’s what the output is meant to look like, notice separate tables for separate rounds:

round robin match listing

  • 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-11T14:27:56+00:00Added an answer on June 11, 2026 at 2:27 pm

    Maybe you mean to group matches by round, like this:

    - @matches.group_by(&:round).each do |round, matches|
      %h1= "Round #{round}"
      %table.table.table-bordered
        %thead
        %tr
          %th.span4 Player 1
          %th.span4 Player 2
          %th.span4 Winner
        %tbody
          - matches.each do |match|
            %tr
              %td= match.register.user.username
              %td= match.register_2.user.username
              %td= match.winner.user.username unless match.winner.nil?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an array with a structure like this: $arr= Array( array(
lets say i have one array a = numpy.arange(8*6*3).reshape((8, 6, 3)) #and another: l
Lets say I have an array numbers that contains the following values: int numbers
Lets say I have an array of length n and I want to pick
Lets say I have an array : a=[[1,2,3],[4,5]] and I have another array :
Ok so lets say I have an array that can be 0 - X
Lets say I have the following array in JavaScript: var skins = new Array('Light',
lets say we have a string[] array = {telekinesis, laureate, Allequalsfive, Indulgence}; and we
Lets say I have a simple 1D array with 10-20 entries. Some will be
Lets say that i have the following array : float QuadVertices[4 * 2]; float

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.