Very weird - Type error where there isn't one?!

Hi all

Put the following code in a view of a Rails app (replace the model
classes in the array with some of your model classes):

<ul class="buttons">
  <% [Country, LinkCategory, Link, Member, MusicArtist, MusicLabel,

MusicStyle, PartySetting, PsyCommunity, OnlineShop, Session,
SystemGroup, SystemRight].each do |clazz| %>
<%= “<li” + (’ class=“selected”’ if clazz.to_s.pluralize +
“Controller” == self.controller.class.to_s) + “>” +
clazz.to_s.tableize.titleize + “” if user_authorized_to?(‘VIEW’,
clazz) %>
<% end %>

You’ll be surprised - you’ll get a TypeError. Now re-arrange the code to
the following:

<ul class="buttons">
  <% [Country, LinkCategory, Link, Member, MusicArtist, MusicLabel,

MusicStyle, PartySetting, PsyCommunity, OnlineShop, Session,
SystemGroup, SystemRight].each do |clazz| %>
<%= “<li” + (’ class=“selected”’ if true) + “>” +
clazz.to_s.tableize.titleize + " #{clazz.to_s.pluralize + “Controller”
== self.controller.class.to_s}" if user_authorized_to?(‘VIEW’,
clazz) %>
<% end %>

Now it works! Same code fragments, but different effect! What’s wrong
here?! Very annoying…

Thanks,
Josh