我不确定这里发生了什么......但是我说这样做:
def who_wins?(choice1, choice2)
if (choice1 == 'R' && choice2 == 'S') || (choice1 == 'S' && choice2 == 'P') || (choice1 == 'P' && choice2 == 'R')
return choice1
elsif choice1 == choice2
return "tie"
else
raise NoSuchStrategyError
end
end
won_wins?('R', 'P')
它给了我以下错误:
NoMethodError: undefined method `won_wins?' for main:Object
at top level in my-file.rb at line 25
为什么会这样做,即使我在定义之后调用方法?
答案 0 :(得分:5)
您输入了won_wins?
而非who_wins?