我不确定这里发生了什么......但是我说这样做:
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')
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误:
NoMethodError: undefined method `won_wins?' for main:Object
at top level in my-file.rb at line 25
Run Code Online (Sandbox Code Playgroud)
为什么它会这样做,即使我在定义之后调用方法?
| 归档时间: |
|
| 查看次数: |
422 次 |
| 最近记录: |