Skip to content

Instantly share code, notes, and snippets.

@pocke
Last active October 19, 2016 12:58
Show Gist options
  • Save pocke/2ce71124da1d8728adbf6ea67fc870ea to your computer and use it in GitHub Desktop.
Save pocke/2ce71124da1d8728adbf6ea67fc870ea to your computer and use it in GitHub Desktop.
Diff between for and each method in Ruby (2.3.1)
p defined? x # => nil
p defined? y # => nil
[1,2,3].each do |x|
x
y = 1
end
p defined? x # => nil
p defined? y # => nil
for x in [1,2,3] do
x
y = 1
end
p defined? x # => "local-variable"
p defined? y # => "local-variable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment