Skip to content

Instantly share code, notes, and snippets.

@fuse
Forked from tight/gist:1758913
Created February 7, 2012 10:51
Show Gist options
  • Save fuse/1759079 to your computer and use it in GitHub Desktop.
Save fuse/1759079 to your computer and use it in GitHub Desktop.
for vs each
i = "foo"
for i in 1..5 do
puts i
j = "bar"
end
i # => 5
j # => "bar"
i = "foo"
(1..5).each do |i|
puts i
k = "bar"
end
i # => "foo"
k # => NameError
i = "foo"
for i in 1..5
lambda {
puts i
l = "bar"
}
end
i # 5
l # NameError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment