From: "David A. Black" Date: 2005-04-22T09:14:42+09:00 Subject: Re: for .. in .. else? 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: >> >> >> >> >> >> <% if song_list.empty? %> >> >> >> >> <% else song_list.each do |song|%> >> >> >> >> <% end %> >> <% end %> >> >>
Songs
no songs!
<%= song.name %>
>> >> 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: > > > > <% unless song_list.each do |song|%> > > <% end.empty? %> > > <% end %> > >
Songs
<%= song.name %>
no songs!
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