Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Created March 25, 2015 03:01
Show Gist options
  • Save samuraijane/b201e2ee704f3ec7afb5 to your computer and use it in GitHub Desktop.
Save samuraijane/b201e2ee704f3ec7afb5 to your computer and use it in GitHub Desktop.
Each is considered better form than a for loop. Although they achieve the same results, the variable in the for loop is retained after it executes (which can make debugging more difficult) while the variable in each only lives inside the block.
<%
for item in ids
puts item
end
%>
<%
ids.each do |item|
puts item
end
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment