Skip to content

Instantly share code, notes, and snippets.

@nelantone
Created January 27, 2021 11:34
Show Gist options
  • Save nelantone/096c46a5d5cfdc15ee1b047083eeec00 to your computer and use it in GitHub Desktop.
Save nelantone/096c46a5d5cfdc15ee1b047083eeec00 to your computer and use it in GitHub Desktop.
Easy example of variable shadowing in ruby collections
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