简单Ruby程序中的错误

时间:2015-03-20 23:41:56

标签: ruby syntax-error

我在使用此代码时遇到了一些麻烦。当我运行它时,它告诉我:

  

意外的$ end,期待}

以下是代码:

puts "You have been contacted, and pooled into a secret orginization. Please select your mode."
puts "Double Agent"
puts "Spy"
Mode_Split = gets.chomp
# This is the turning point.
if Mode_Split = "Double Agent"
puts "Your job is to return data points from the FXR (Free Xutopian Republic) to the SU (Shared Union)."
Agency_Members = [["HEAD OF AGENCY", "Robin Woods" "AKA: Dexter"],["HIGHER UPS", "Bryan Silk", "AKA: Silk Road", "Voilet Blue", "AKA: Hydraog"],["AGENTS","Alex Cooper", "Matt Syon", "Jack Cumberland" "Mike Schmidt", "Frits Fitsgerald"],["SUSPECTED DOUBLE AGENTS", "Jack Cumberland"]]
Agency_Members.each { |X| puts Agency_Members }

2 个答案:

答案 0 :(得分:3)

应该解决一些问题:

在回答你的问题时,你错过了'if'

的'结束'

if <condition> stuff in here end

您还需要将大写'X'更改为小写。大写变量表示常量,因此大写“X”不能用作块索引。

Ruby约定是对变量名使用小写/ snake case,因此Mode_SplitAgency_members应为mode_splitagency_members

答案 1 :(得分:0)

我认为你在end声明之后遗漏了if。我不确定你要在哪里结束这个陈述,但你需要做一些像:

if Mode_Split = "Double Agent" 
  puts "Your job is to return data points from the FXR (Free Xutopian Republic) to the SU (Shared Union)."
  Agency_Members = [["HEAD OF AGENCY", "Robin Woods" "AKA: Dexter"],["HIGHER UPS", "Bryan Silk", "AKA: Silk Road", "Voilet Blue", "AKA: Hydraog"],["AGENTS","Alex Cooper", "Matt Syon", "Jack Cumberland" "Mike Schmidt", "Frits Fitsgerald"],["SUSPECTED DOUBLE AGENTS", "Jack Cumberland"]]
  Agency_Members.each { |X| puts Agency_Members }
end