Created
January 27, 2021 11:34
-
-
Save nelantone/096c46a5d5cfdc15ee1b047083eeec00 to your computer and use it in GitHub Desktop.
Easy example of variable shadowing in ruby collections
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
greet_var = "Hi there" | |
loop do |greet_var| # |greet_var| block parameter | |
greet_var = "What's up from the block" # inner scope `greet_var` | |
end | |
greet_var # => "Hi there" # the outer sope variable is protected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment