Sorry, there are no things
You know when there's something in the back of your mind, something you want to check out that you never get around to? Here's one from why that just made my day!
things = [1,2,3] if things.each do |thing| puts thing end.empty? then puts "no things!" end
It takes the classic case of if there's things, use the things, otherwise do something completely different and makes it beautiful. This is extra handy in ERB since there's only three lines of logic instead of five. (Note using the for..in alternative as well).
<% if for thing in things %> <%= thing %> <% end.empty? then %> no things <% end %>
Bonus points for anyone that can write the following more simply...
<% unless things.empty? %> <ul> <% for thing in things %> <li><%= thing %></li> <% end %> </ul> <% else %> no things <% end %>
Note for Typo + MarsEdit people
If you're using Typo with MarsEdit, and have been bitten by the can't edit my post after it's been published bug, you need to apply this patch or upgrade your Typo installation.
Thanks everyone with Ranchero and Typo that figured it out! We all know that ./script/console is cool but using it to edit your posts gets old quick.
Update - Just to prove it works!