Created
April 13, 2012 15:29
-
-
Save jasonknight/2377719 to your computer and use it in GitHub Desktop.
Inheritance vs NameSpace
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
module SomeThing | |
class SomethingElse;end | |
def self.inside | |
x = AllTogetherDifferent.new | |
# Works because all constants are Global | |
puts x.inspect | |
# x = SomeThing::AllTogetherDifferent.new | |
# Produces in `inside': uninitialized constant SomeThing::AllTogetherDifferent (NameError) | |
x = SomeThing::SomethingElse::AllTogetherDifferent.new | |
puts x.inspect | |
# Works! but generates a warning | |
end | |
end | |
class AllTogetherDifferent < SomeThing::SomethingElse;end | |
# inst = SomeThing::AllTogetherDifferent.new | |
# in `<main>': uninitialized constant SomeThing::AllTogetherDifferent (NameError) | |
SomeThing.inside |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment