I'm building a tic tac toe game in Ruby. To determine if someone has won the game, I have a 2d array, check_array, of all of the possible sets you could use to win. I want to see if any of those arrays in check array have all the same elements. My javascript brain is having a hard time figuring out how to do this in Ruby. I'm confused without my curlies to delineate the block. I understand this sort of syntax:
if check_array.any? {|row|row.uniq.count == 1}
@winner = @whos_turn
winning
end
But what if I need to use more than one line of logic for my any? logic. Could it look like this?
if check_array.any? do |row|
row.uniq.count == 1
<<some more code>>
end
@winner = @whos_turn
winning
end
<<some more code>>should probably be outside ofany?'sdoend.any?returns true, theifwill be true. Since the block can contain as much code (and logic) as you want, you can do inside it what you want.