So, pretend we have the following three methods that check a grid to determine if there is a winner, and will return true if there is.
def win_diagonal?
# Code here to check for diagonal win.
end
def win_horizontal?
# Code here to check for horizontal win.
end
def win_vertical?
# Code here to check for vertical win.
end
I would like to push the returned values of each method into an Array instead of literally using the method names. Is this possible?
def game_status
check_wins = [win_vertical?, win_diagonal?, win_horizontal?]
if check_wins.uniq.length != 1 # When we don't have only false returns from methods
return :game_over
end
end
if win_vertical? || win_diagonal? || win_horizontal?— that way you don't need the array or the less direct test.if win_vertical? || win_diagonal? || win_horizontal?" will always return:game_overan example:irb(main):005:0> puts "hi" if 1 || 2 || 3 == 5 hiif false || false || true— this assumes your methods returntrueorfalse. You don't need==anything.