module Hints
module Designer
def self.message
"Hello, World!"
end
end
end
is there any way to use the following code to access the message method?
p Hints.Designer.message
Instead of
p Hints::Designer.message
The period
.is only meant for accessing methods.The double colon
::is used to indicate namespaces.Both modules and classes can be nested in each other. This creates a namespace for the nested class. (Technically, Module is an instance of Class.) Thus, the following is correct no matter if Hints or Designer are a class or a module.
You can try yourself by opening
irbon the command line.Hints.Designer.messagesaysNoMethodError: undefined method 'Designer' for Hints:Module.Update (as I am not allowed to comment…):
While many things in Ruby can be overwritten (“monkey patched”), basic operators cannot.
::is a basic language feature that is and should not be customizable (in order to prevent a big mess ;)).