views:

36

answers:

2

I'm having a lot of trouble with Ruby after coming back to it from a long break.

I'm getting a lot of 'unexpected kEND' errors, and I've tracked it down to lines below. I'm not having trouble with a particular piece of code, but rather, the concept of 'unexpected kEND' .

if (condition)
  do-one-line-thing()

and

# inside of a loop...
if ( condition-evaluation-that-might-cause-error-during-run-time )
  do-something()
end

and

myarray.each { |element|
   do-soemthing-that-might-cause-error-during-run-time-for-some-but-not-all-values()
}

Question :

What other things can cause these kEND errors ? It seems like kEND is being used as a general "Badness on line ##" error? What can you tell me about kEND errors in general?

+1  A: 

an unexpected kEND is where the end keyword was found somewhere it shouldn't be.

Generally you've closed too many code blocks, or you've got some other syntax problem.

If you paste a (complete) file which has this problem we can point out the error...

Gareth
Right, but, in my code, which has no syntax problems, when there is an error inside evaluation/execution, I seem to get a kEnd error, rather than a message like 'error: can't cast nil to specific type!', so I'm asking to find out more about this odd seemingly odd error...
rlb.usa
unexpected kEND **is** a syntax error. Pastebin an entire file which has this problem and we'll try and help
Gareth
@rlb.usa: Making claims like "my code has no syntax problems" is not very helpful when you're encountering an error you can't explain. You're obviously making *some* mistake without realizing it or else you wouldn't have a problem. (Incidentally, the first code snippet you posted is actually missing an `end`.)
Chuck
Actually, I think you are right. There were some syntax errors in conditional statements, so the syntax error messages only came up once in a while when the right conditions were met.
rlb.usa
A: 

There is a syntax error in the first piece of code

if (condition)
  do-one-line-thing()

You always have to explicitly close the if clause with end. You cannot omit it, like you do in many other languages, even if the block consists of a single line.

Adam Byrtek