Douglas Livingstone a ˝─rit :
> In my erb templates, I've got this pattern quite often:
> 
> <table>
> <th>Songs</th>
> <% for aSong in songList %>
> <td><%= aSong.name %></td>
> <% end %>
> <% unless songList.empty? %>
> <td>no songs!</td>
> <% end %>
> </table>
> 
> Is there any way to write is more like this:
> 
> <table>
> <th>Songs</th>
> <% for aSong in songList %>
> <td><%= aSong.name %></td>
> <% else %>
> <td>no songs!</td>
> <% end %>
> </table>
> 

<table>
<th>Songs</th>
<% (songList.empty? ? ["no songs!"] : songList).each do |aSong| %>
<td><%= aSong %></td>
<% end %>
</table>

-- 
Lionel Thiry

Personal website: http://users.skynet.be/lthiry/