Ghost Project, single line conditionals (if / unless) and unexpected end errors

Code Sample

I was redoing my Ghost project after doing the next unit, trying to clean up my code. While doing that I ran into a bug that I do not understand. I keep getting an “unexpected keyword_end, expecting end-of-input error” with this code.

I could not find the error so I created a new file and began retyping in the methods, testing each one as I went. Doing this I hit a road block when I entered the display_game_state method.

Everything works fine until I add that last method. The error appears every time I run the code in pry after it’s added. if I try to call it I get a NoMethodError. As far as I can tell all of my methods and blocks are properly closed with end.

I would very much like to understand what is happening here.

EDIT: I strongly suspect that there is something strange going on with the single line if statements, like the one in upadate_game_state and the one I commented out in display_game_state. The code highlighters in both VS code and Sublime want to associate the if statement with the end statement for that method.

However, update_game_state functions properly when the class is tested in pry. Methods that come after it also execute properly. word_complete? and prompt_choice_redo both function properly.

The errors begin to appear once display_game_state is added to the class. The appear whether I use a single line if statement in that method or not.


While I did find an out of place bracket in the display_game_state method, fixing it did not solve the problem. I was able to fix it by removing all single line if and unless statements. from the code.

How do single line conditionals work in Ruby? Why was including them in my code causing “unexpected end” errors?

This version of the code does not give me any errors in pry.

Edit 3: I’ve got the code working now. I fixed the out of place brace, but was still getting an error. It started working after I deleted a comment and changed the display_game_state method back to a single line conditional. I’m not sure what was going on. But to anyone else that runs into something like this all I have to say is, check your braces and parentheses again.
I’ve got the code working

I have run into errors where an end will have a invisible line break after it and cause an error. I typed the entire code over again and it worked fine so I went to a difference checker website and pasted both identical codes in. The code that failed showed the extra line break immediately after end. Again, this break was an invisible break and sure enough when I backspaced the extra break the code worked fine.
I believe the extra line break came from copying and pasting the code in slack.