Ruby-on-rails – in Ruby on Rails, what is the kENSURE and kEND in error messages

rubyruby-on-rails

In Ruby on Rails, I sometimes get an error on the page as:

compile error
/Users/jian/ror/shov2/app/views/stories/index.html.erb:13:
syntax error, unexpected kENSURE,
expecting ')'
/Users/jian/ror/shov2/app/views/stories/index.html.erb:15:
syntax error, unexpected kEND,
expecting ')'

the kEND, i can guess that it is End… so it means End of file but unexpected, there should be a ')'.

how about the kENSURE ?

Best Answer

The kEND constant refers to the token "end", as in what you end every code block with. An ensure block is the equivalent of a finally block in other languages.

begin
  1/0
rescue ZeroDivisionError
  puts "OH SHI-"
ensure # <- THIS THING
  1/1
  puts "Whew, we're safe"
end

That's what kENSURE refers to.

It sounds like you forgot to put the closing paren at the end of either a method call or a method parameter list.