Skip to content

Instantly share code, notes, and snippets.

@sbounmy
Created March 14, 2015 10:50
Show Gist options
  • Save sbounmy/75b08c401e7957abe7a3 to your computer and use it in GitHub Desktop.
Save sbounmy/75b08c401e7957abe7a3 to your computer and use it in GitHub Desktop.
Ruby constant lookup
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