Ruby nested classes and modules

I am familiar with the concept of nested classes and modules inside another module and grouping them in a namespace. What is the idea / goal behind

  • Nested classes inside another class

    class A
      class B
        def method_B
          ...
        end
      end
    end
    
  • Nested modules inside another class

    class A
      module c
        def method_c
          ...
        end
      end
    end
    

thanks ash

+3
source share
2 answers

Classes are also namespaces, so the same idea. A class is a subclass of a module, so if you get it in the context of modules, you also get it in the context of classes.

+3
source

, . 1 HTTP:: Request ( , HTTP) - FTP:: Request. Behavior:: InstanceMethods Behavior:: ClassMethods .

+1

Source: https://habr.com/ru/post/1745409/


All Articles