Last active
October 19, 2016 12:58
-
-
Save pocke/2ce71124da1d8728adbf6ea67fc870ea to your computer and use it in GitHub Desktop.
Diff between for and each method in Ruby (2.3.1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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