What is the relationship between the ruby class and a module of the same name?
The class and module cannot have the same fully qualified name in ruby. It is possible to have a Foo::Bar class and a Baz::Bar module, in which case there is no connection between the class and the module. However, it is not possible to have the Foo::Bar class and the Foo::Bar module at the same time.
(I'm not sure if this is relevant to the rest of your question though)
Is my inclusion string in Foo necessary or does Rails automatically include these modules?
Rails does not automatically include your modules. However, this does not mean that you need to turn on yourself, you can simply access it. That is, use Exceptions::MySpecialException instead of MySpecialException inside the Foo class.
Why does a MySpecialException exist in the top-level Foo namespace and point to Foo :: Exceptions :: MySpecialException?
Because you included Foo::Exceptions in Foo . Because of this, all instance methods of Foo::Exceptions are also instances of the Foo method, and all Foo::Exceptions constants are also Foo constants - including MySpecialException .
What does it mean that these two classes ==, but not ===?
== means that it is the same class. The fact that this is not === means that the class is not an instance of itself (since x === y matches y.is_a?(x) if x is a class).
source share