Hi -- On Fri, 22 Apr 2005, Hal Fulton wrote: > Ryan Leavengood wrote: >> >> The above works (I tested it) but I think this is more Rubyish: >> >> <table> >> <tr> >> <th>Songs</th> >> </tr> >> <% if song_list.empty? %> >> <tr> >> <td>no songs!</td> >> </tr> >> <% else song_list.each do |song|%> >> <tr> >> <td><%= song.name %></td> >> </tr> >> <% end %> >> <% end %> >> </tr> >> </table> >> >> i.e. get rid of the for entirely. > > I don't object to the 'for' (although I know some don't like it). I don't usually like it, but for some reason I find myself sometimes using it (and in this case not really noticing it was there) in these templates. I wonder if it's because <% list.each do |item| %> feels weirdly truncated, visually. I don't know. > FWIW I'll offer this (untested) alternative: > > <table> > <tr><th>Songs</th></tr> > <% unless song_list.each do |song|%> > <tr><td><%= song.name %></td></tr> > <% end.empty? %> > <tr><td>no songs!</td></tr> > <% end %> > </tr> > </table> Interesting -- there was some IRC chatting the other day about the question of whether the return value of Array#each was ever used. I don't think anyone could think of an example, but now we've got one :-) David -- David A. Black dblack / wobblini.net