These two writing methods are often confused.
First of all, I must say that, as far as I know, there is no measurable difference in performance. (one constant search in the example below)
The most obvious difference, perhaps the most famous, is that for the second example ( module A::B ), it is required for module A exist during the definition.
Otherwise, most people consider them interchangeable. This is not true .
Modules are just constants in ruby ββand therefore regular, constant searches are applied.
Let me show this with an example:
module A class Test end module B class Show p Module.nesting
On the other hand, if you call it through A::B , see what happens:
module A class Test end end module A::B class Show p Module.nesting
The difference is that .nesting produces:
1) in the first case: [A::B::Show, A::B, A] (you are nested in module A )
2) in the second case: [A::B::Show, A::B] (not here)
source share