21

I am currently on Lesson 9 in "Learn Ruby the hard way".

I have typed the the line number 6 exactly as the way its being instructed but still I am getting error while executing.

It says:

Syntax error, unexpected tCONSTANT, expecting $end
puts " Here ^ are the days : ", days 
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
The Realmccoy
  • 329
  • 1
  • 2
  • 9
  • This can happen in IRB (interactive ruby) even if I've hit Ctrl-C several times. I find I just exit IRB if I hit this in IRB. – Warren P Oct 08 '16 at 17:44

2 Answers2

27

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).

Paul Annesley
  • 3,387
  • 22
  • 23
6

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675