Skip to content

Instantly share code, notes, and snippets.

@a-chernykh
Created October 16, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-chernykh/cd9f3cfe085991e5650d to your computer and use it in GitHub Desktop.
Save a-chernykh/cd9f3cfe085991e5650d to your computer and use it in GitHub Desktop.
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