using join looks like will create only n + 1 string objects...
ah, on second thought, doesn't the join() method actually will create n
string objects too? (the next one longer than a previous one), so it
would be creating 2n string objects too.
<% @stories.each do |s| %>
<%= "<div>#{h s.inspect}</div>" %>
<% end %>
Another option, although probably not necessary in this case, is to move
the code into a view helper.
<%= h story_list(@stories) %>
def story_list(stories)
list = ""
stories.each do |s|
list += content_tag(:div, h(s.inspect))
end
list
end
Yes, in this case the helper is more verbose (maybe there's a better way
that what I did), but at least your view code is clean and pretty. The
ugliness get move outside the view into the helper.
Another common pattern for a case like you show is to move the code that
actually lists the stories into a partial. Then rendering the partial
from your view becomes one line: