Skip to content

Instantly share code, notes, and snippets.

@samuraijane
Created March 25, 2015 00:36
Show Gist options
  • Save samuraijane/d5450e1b1d14d5ff5aa8 to your computer and use it in GitHub Desktop.
Save samuraijane/d5450e1b1d14d5ff5aa8 to your computer and use it in GitHub Desktop.
An `each` statement is basically a loop in which you can define a variable. However, you can only use that variable within the statement itself. If you need that variable outside of the statement, use `do`.
#Each statements do not allow their variables to be used outside of the statement.
<%= friends.each{|friend| friend['children']} %>
#To do this use `do`.
<% friends.each do
|friend| @uno = friend['name']
end %>
<%= "#{@uno}" %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment