Ruby - Populate and Array with returned method values -
so, pretend have next 3 methods
check grid determine if there winner, , homecoming true
if there is.
def win_diagonal? # code here check diagonal win. end def win_horizontal? # code here check horizontal win. end def win_vertical? # code here check vertical win. end
i force returned values of each method array
instead of literally using method names. possible?
def game_status check_wins = [win_vertical?, win_diagonal?, win_horizontal?] if check_wins.uniq.length != 1 # when don't have false returns methods homecoming :game_over end end
what looking indeed work in ruby.
def hello_world? "hello world!" end = [hello_world?]
prints out
=> ["hello world!"]
hope helps. irb
friend when wonder if possible in ruby :-)
ruby arrays function methods
No comments:
Post a Comment