rlb.usa
rlb.usa

Reputation: 15043

About Ruby error 'kEnd'?

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?

Upvotes: 3

Views: 3556

Answers (2)

Adam Byrtek
Adam Byrtek

Reputation: 12202

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.

Upvotes: 0

Gareth
Gareth

Reputation: 138042

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

Upvotes: 3

Related Questions