RE: templates and arrays


#1

The best way to do this is:

<% products.each_with_index { |product, index| %>
<%= product.size %>
<% } %>

You should forget for, it is not needed in Ruby Land. Enumerations
such as each are more efficient when you get to more interesting cases

Forget the For loop - it’s so 1998!


#2

Tom F. wrote:

The best way to do this is:

<% products.each_with_index { |product, index| %>
<%= product.size %>
<% } %>

I would use the do/end syntax in place of the { } since you are having
it span multiple lines, and
since embedded in html. It is somewhat ambiguous because hashes can be
created with {}.

<% products.each_width_index do |product,index| %>
<%= product.size %>
<% end %>

I think ‘end’ in embedded in HTML also gives a better visual for way a
code block stops in ruby.

Zach