我想修改一个脚本来包含一个case块,但是每当我这样做,我似乎得到这个错误。我最初认为这是因为我错过了某个地方的结局,但我检查了我的整个代码,看起来好像很好。Ruby:语法错误,意外的keyword_when,期待输入结束
工作(前加入的情况下):
def determine_grade
Console_Screen.cls #Clear the display area
#To pass the test the player must correctly retype 3 sentences
if $noRight >= 6 then
#Inform the player of the good news
print "You retyped " + $noRight.to_s + " sentence(s)" +
"correctly. "
puts "You have passed the typing test!\n\nPress Enter" +
"to continue."
else #The player has failed the test
#Inform the player of the bad news
print "You retyped " + $noRight.to_s + " sentence(s)" +
"correctly. "
puts "You have failed the typing test!\n\nPress Enter
to continue."
end
end
end
后:
def determine_grade
Console_Screen.cls #Clear the display area
#To pass the test the player must correctly retype 6 sentences
case $noRight
when 9 || 10
print "You get an A!"
end
when 8
print "You get a B!"
end
when 7
print "You get a C."
end
when 6
print "You get a D."
end
when <= 5
print "You get an F."
end
else
print "Error"
end
end
end
end
任何想法?
**缩进**请!如果错误是可见的,你会发现这样的错误。这一切完全混乱是一个巨大的问题。第二件事是避免使用全局变量,除非它是绝对必要的。 Ruby的'$ x'不像PHP或Perl等价物那样只是一个变量,'$'前缀意味着全局。此外,Ruby风格建议对方法和变量名使用'no_right',所有小写都带下划线,因为在Ruby中情况具有重要意义。 – tadman