Some times I see code like this:
module Elite
module App
def app
'run app'
end
end
module Base
def base
'base module'
end
end
class Application
include Elite::Base #Include variant A
include ::Elite::App #Include variant B
def initialize(str=nil)
puts "Initialized with #{str}"
puts "Is respond to base?: #{base if self.respond_to?(:base)}"
puts "Is respond to app?: #{app if self.respond_to?(:app)}"
end
end
class Store < ::Elite::Application
def initialize(str=nil)
super #Goes to Application init
end
end
end
elite = Elite::Store.new(:hello)
But I don’t understand what’s different between class Store < ::Elite::Application and class Store < Elite::Application or include Elite::Base and include ::Elite::App
Is it only coding style, or ìs it something different?
What does :: do before Class/Module? :: clean namespace (module name) for class/module? Because class Store < Application works, but this doesn’t: class Store < ::Application. Please tell me what’s the difference… Thanks!
‘::’ is the base(global) scope operator.
So ‘::Application’ references the base Application where as ‘Application’ references Application in the current scope.
For example