我得到了这些错误 -因式分解红宝石中的多项式练习,意外的语法?
(eval):30: (eval):30: compile error (SyntaxError)
(eval):8: syntax error, unexpected kDO
- 当我跑在控制台这个Ruby代码 -
class Factor
puts "This program will factor a polynomial in the form of \"Ax^2 + Bx + C.\""
aPos = PosOrNeg?("A")
# test
puts aPos
def PosOrNeg?(string = "blank") do
puts "Tell us if \"#{string}\" is positive or negative. Type \"pos\" or \"neg\"."
posOrNegStr = gets.chomp
case posOrNegStr
when "pos"
pos = true
when aPosOrNegStr = false
pos = false
else
while posOrNegStr != "pos" && posOrNegStr != "neg" do
puts "Invalid input. Please type \"pos\" or \"neg\"."
posOrNegStr = gets.chomp
case posOrNegStr
when "pos"
pos = true
when aPosOrNegStr = false
pos = false
else
end
end
end
end
end
的思考?
从行删除'do':def PosOrNeg?(string =“blank”)'然后尝试 – Surya 2014-10-08 18:02:54
你的问题是什么? – sawa 2014-10-08 18:12:38
值得注意的是,Ruby方法和变量应该遵循'lower_case_with_underscores'约定。使用大写字母是不寻常的,正如您在这里看到的,会混淆语法突出显示。 – tadman 2014-10-08 18:18:16