I was writing some code in an erb template that looked like this:
This resulted in a syntax error. Huh? What's wrong with this?
Turns out it's an outstanding Core Ruby bug.
As shown in the ticket if we have a method foo
using the ! and the not operator on various method calls show us that the ! and not operator are not interchangeable in practice.
Changing the my code to the following fixed my issue:
<% if @user && not @user.errors.empty? -%> #do stuff <% end -%>
def foo(parameter) puts parameter.to_s end
foo(!(1 < 2)) # works fine foo(not(1 < 2)) # generates syntax error foo(not 1 < 2) # generates syntax error foo((not 1 < 2)) # works fine
<% if @user && !@user.errors.empty? -%> #do stuff <% end -%>