Ruby:语法错误,意外的 tIDENTIFIER,期待 ')'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17507330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:03:34  来源:igfitidea点击:

Ruby: syntax error, unexpected tIDENTIFIER, expecting ')'

rubysyntax

提问by emco

Working on exercise #26 of Learn Ruby The Hard Way -- correcting a ficticious programmer's bad code.

练习 Learn Ruby The Hard Way 的练习 #26 —— 纠正一个虚构的程序员的错误代码。

I've got most of it worked out, but can't even get to testing because I keep getting this syntax error:

我已经完成了大部分工作,但甚至无法进行测试,因为我不断收到以下语法错误:

syntax error, unexpected tIDENTIFIER, expecting ')'

...on this line:

...在这一行:

sentence = "All good\tthings come to those who wait."

I thought that was always the way variables were declared? Since the error was listing parens, I tried those too -- around sentence (even though it made no sense), around the string (both with and without quotes), with the equals sign, without the equals sign...I'm not really sure what the issue is here.

我认为这总是声明变量的方式?由于错误是列出括号,我也尝试了这些 - 围绕句子(即使它没有意义),围绕字符串(带和不带引号),带等号,不带等号......我不太确定这里的问题是什么。

回答by Stas S

Not always errors are on the same lines as interpreter says ;) So it would be better if you include some adjacent lines next time. But as I found these lines are:

错误并不总是与解释器说的在同一行上;) 因此,如果下次包含一些相邻的行会更好。但正如我发现这些行是:

puts "We can also do that this way:"
puts "We'd have %d beans, %d jars, and %d crabapples." % secret_formula(start_pont

sentence = "All god\tthings come to those who weight."

words = ex25.break_words(sentence)
sorted_words = ex25.sort_words(words)

From here we see that the line before your specified line doesn't have closing parenthesis ')'.

从这里我们看到指定行之前的行没有右括号“ )”。