Skip to content

Instantly share code, notes, and snippets.

@jasonknight
Created April 13, 2012 15:29
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 jasonknight/2377719 to your computer and use it in GitHub Desktop.
Save jasonknight/2377719 to your computer and use it in GitHub Desktop.
Inheritance vs NameSpace
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