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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:13:33+00:00 2026-05-31T08:13:33+00:00

So, say I have an array that looks like this: t = [ [

  • 0

So, say I have an array that looks like this:

t = [
      [
        [["Armando", "P"],["Dave", "S"]],
        [["Richard", "R"],["Michael", "S"]],
      ],
      [
        [["Allen", "S"],["Omer", "P"]],
        [["David E.", "R"], ["Richard X.", "P"]]
      ]
    ]

Basically, I want to evaluate each inner array that has an array of two elements – e.g. the first one in the code snippet above is Armando, and Dave. Both of those are two elements in one array, which is the first element in a parent array.

What I want to do is take that first ‘sub-array’, and assign it to a variable. Pass that variable to another method I have (say my_method), which will then return only one of those elements in the sub-array.

I think I want to use yield but I am not quite sure how to do that.

I was thinking something like this:

t.each do |entry|
  a = entry
  yield my_method(a) 
end

But I am getting confused with the hand-off of the yield and the hella complex arrays.

How do I get what I am looking for?

Edit 1: This is what I am doing with t, but am still getting an error that indicates that I am doing something wrong with the yield and such.

This is my main method that will be evaluating t:

def rps_game_winner(game)
    raise WrongNumberOfPlayersError unless game.length == 2
    if (game[0][1] =~ /[r]/i && game[1][1] =~ /[s]/i) || (game[0][1] =~ /[s]/i && game[1][1] =~ /[p]/i) || (game[0][1] =~ /[p]/i && game[1][1] =~ /[r]/i)
        return game[0]
    elsif (game[0][1] =~ /[r]/i && game[1][1] =~ /[p]/i) || (game[0][1] =~ /[s]/i && game[1][1] =~ /[r]/i) || (game[0][1] =~ /[p]/i && game[1][1] =~ /[s]/i)
        return game[1]
    elsif game[0][1] == game[1][1]
        return game[0]
    else
        raise NoSuchStrategyError.new
    end
end

def rps_tournament_winner(t)
   t.each do |pair|
    yield pair
   end  
end

rps_tournament_winner(t) { |x| rps_game_winner(x)  }

So the error I am getting is: NoSuchStrategyError: NoSuchStrategyError – which means that the yield is passing a value to the block and that is being passed to my method rps_game_winner and it is evaluating something and giving that error – per the method. But it’s not evaluating it properly….because it should be looking at Armando and Dave and returning a winner, then it should go back and continue look at the next pair and return the winner, etc.

Any ideas why this isn’t working?

  • 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-31T08:13:34+00:00Added an answer on May 31, 2026 at 8:13 am

    SEE EDIT BELOW

    I’m not exactly sure what you want to do with the yielded names, but I’ve prepared an example for you that extracts all the first names, using yield, that you can adapt to your own needs:

    t = [
          [
            [["Armando", "P"],["Dave", "S"]],
            [["Richard", "R"],["Michael", "S"]],
          ],
          [
            [["Allen", "S"],["Omer", "P"]],
            [["David E.", "R"], ["Richard X.", "P"]]
          ]
        ]
    
    def get_name_pairs(t)    
      t.each do |a|
        a.each do |x|
          yield x[0], x[1]
        end
      end
    end
    
    def print_first_names(person1, person2)
      puts person1[0]
      puts person2[0]
    end
    
    get_name_pairs(t) {|x, y| print_first_names(x, y)}
    

    EDIT

    Now that the OP clarified the problem, here is the fix. (The problem was that nested blocks were needed to get into the game):

    # HEY IT IS ROCK PAPER SCISSORS!
    t = [
      [
        [["Armando", "P"],["Dave", "S"]],
        [["Richard", "R"],["Michael", "S"]],
      ],
      [
        [["Allen", "S"],["Omer", "P"]],
        [["David E.", "R"], ["Richard X.", "P"]]
      ]
    ]
    
    def rps_game_winner(game)
      raise WrongNumberOfPlayersError unless game.length == 2
      if (game[0][1] =~ /[r]/i && game[1][1] =~ /[s]/i) ||
          (game[0][1] =~ /[s]/i && game[1][1] =~ /[p]/i) ||
          (game[0][1] =~ /[p]/i && game[1][1] =~ /[r]/i)
        return game[0]
      elsif (game[0][1] =~ /[r]/i && game[1][1] =~ /[p]/i) ||
          (game[0][1] =~ /[s]/i && game[1][1] =~ /[r]/i) ||
          (game[0][1] =~ /[p]/i && game[1][1] =~ /[s]/i)
        return game[1]
      elsif game[0][1] == game[1][1]
        return game[0]
      else
        raise NoSuchStrategyError.new
      end
    end
    
    def rps_tournament_winner(t)
      t.each do |level|
        level.each do |game|
          yield game
        end
      end  
    end
    
    rps_tournament_winner(t) { |x| puts rps_game_winner(x)  }
    

    This outputs

    Dave
    S
    Richard
    R
    Allen
    S
    Richard X.
    P
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, I have an array that looks like this: var playlist = [ {artist:Herbie
Let's say I have an array that looks like this: $array[0] = 'House'; $array[1]
Let's say you have an array that looks like this: $myArray []= array('firstname' =>
I have a Javascript array of 20 RGB color values that looks like this:
I have an array that looks like this: Array ( [0] => Array (
Say I have an array that looks like: a = [cat, dog, cat, mouse,
Let's say you have a string that looks like this: token1 token2 tok3 And
Let's say I have a table called my_table that looks like this: id |
Let's say that I have a object that looks like this var object =
I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;

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.