Created
March 14, 2015 10:50
-
-
Save sbounmy/75b08c401e7957abe7a3 to your computer and use it in GitHub Desktop.
Ruby constant lookup
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
Document = 'hello' | |
class Question | |
end | |
class Animal | |
puts Question::Document | |
end | |
class Question | |
class Document | |
end | |
end | |
--output:-- | |
1.rb:7: warning: toplevel constant Document referenced by Question::Document | |
hello | |
It looks like ruby searches enclosing scopes for a constant when it isn't found in the specified scope. I think the warning is a penalty for being unable to think up more than two variable names. | |
Note: If top level constant is required/defined first, it will be used instead of namespaced one |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment