Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
variable in ruby shadows method with the same name
class Tester
def test
if false
# variable 'var' is now in scope because it's defined syntactically (at parse time)
var = 'bar'
end
# variable 'var' shadows method with the same name. variable 'var' was defined, but never assigned which means it equals nil
puts var.inspect # => nil
end
def var
'foo'
end
end
Tester.new.test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.