What is “Syntax Error, unexpected tCONSTANT” error in Ruby?

血红的双手。 提交于 2019-12-04 22:48:30

You have forgotten to close a string on a previous line. Here's the problem reproduced:

paul@paulbookpro ~ ⸩ ruby     
days = "abc
puts "Here are the days"
-:2: syntax error, unexpected tCONSTANT, expecting $end
puts "Here are the days"
          ^

It's treating the double-quote before the word "Here" as the closing quote of the string on the previous line, and then wondering why you're using a constant called Here (token beginning with upper case letter).

The error message means that the ruby parser encountered a constant (i.e. an identifier starting with a capital letter) where it did not expect one (specifically the parser expected the file to end at that point).

Since the code you've shown does not even contain a constant, the problem is likely caused by another part of your code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!