Last active
June 12, 2021 07:15
-
-
Save JonathanWThom/3f44c1daae9d41adf3397cdccf60ed31 to your computer and use it in GitHub Desktop.
Ruby shadowing method example
This file contains 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
# https://thomasleecopeland.com/2017/04/20/shadowing-bug-in-the-wild.html | |
# https://docs.ruby-lang.org/en/2.4.0/syntax/assignment_rdoc.html#label-Local+Variables+and+Methods | |
# https://www.codinginthecrease.com/news_article/show/307337 | |
class Okay | |
def yep | |
"yep" | |
end | |
def nope | |
puts "yep: #{yep}" | |
if false | |
yep = "nope" | |
end | |
puts "yep: #{yep}" | |
end | |
end | |
Okay.new.nope | |
# yep: yep | |
# yep: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment