0
@hands = [

  [{"suit": "heart", "value": 5},{"suit": "heart", "value": 8},{"suit": "spade", "value": 1},{"suit": "club", "value": 5},{"suit": "diamond", "value": 5}],
  [{"suit": "club", "value": 1},{"suit": "club", "value": 3},{"suit": "club", "value": 8},{"suit": "club", "value": 9},{"suit": "club", "value": 11}],
  [{"suit": "diamond", "value": 2},{"suit": "heart", "value": 2},{"suit": "spade", "value": 2},{"suit": "club", "value": 6},{"suit": "diamond", "value": 12}],
  [{"suit": "club", "value": 2},{"suit": "heart", "value": 3},{"suit": "spade", "value": 5},{"suit": "club", "value": 4},{"suit": "diamond", "value": 1}]
]

def get_hands
  @hands.each do |hand|
    hand.each do |card|
      print "#{card.fetch(:suit).chars[0]}" + "#{card.fetch(:value)}"
    end
  end
end

Output of get_hands is:

h5h8s1c5d5c1c3c8c9c11d2h2s2c6d12c2h3s5c4d1

Is there any way? that I can save the values from each hash hand so that I can push the 5 cards from each hand into their own variable. eg: Hand1, Hand2 etc?

I am a Ruby beginner and have been going round and round for few hours, now trying different things to get to even this point. I am just getting confused with my thought process from going round in circles.

ajay_speed
  • 79
  • 9
  • Sure. Make `hand1` and Array or Set, where each element is a card. – user1934428 Nov 18 '22 at 08:25
  • Why would you need `hand1`, `hand2`, ... hardcoded variables? You can always refer to the i-th "hand" in you array via `@hands[i]` instead. Also, it is not clear what do you mean by "save values from each hash hand" - could you please what is the desired output? Is it what `get_hands` does now and you only want it to be done separately for each hand? – Konstantin Strukov Nov 18 '22 at 08:58

0 Answers0