Created
September 29, 2012 19:39
-
-
Save broquaint/3805031 to your computer and use it in GitHub Desktop.
Ruby's variable scope is not what I expect
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
$ cat > var-test.rb | |
s = 'yay?' | |
def f | |
puts s | |
end | |
f | |
$ ruby var-test.rb | |
var-test.rb:3:in `f': undefined local variable or method `s' for main:Object (NameError) | |
from var-test.rb:5:in `<main>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment