Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created July 13, 2012 16:28
Show Gist options
  • Save myronmarston/3105803 to your computer and use it in GitHub Desktop.
Save myronmarston/3105803 to your computer and use it in GitHub Desktop.
for for_i in [1, 2, 3]
end
puts "Variable from for: #{for_i.inspect}"
[1, 2, 3].each do |each_i|
end
puts "Variable from each: #{each_i.inspect}"
➜ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
➜ ruby for_vs_each.rb
Variable from for: 3
for_vs_each.rb:9:in `<main>': undefined local variable or method `each_i' for main:Object (NameError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment