Ruby, why use a module inside a module?

Trying to perform RemoteAuthetation using development, I came across an example (almost official, since the devile wiki is limited to the link to this document ).

All classes that actually implement the authentication algorithm, "deuces" are enclosed in Devise, Models or Devise, Strategies.
Here is an example of Devise, Models:

module Devise
  module Models
    module RemoteAuthenticatable

      extend ActiveSupport::Concern

      def remote_authentication(authentication_hash)
        # Your logic to authenticate with the external webservice
      end

    end
  end
end

: - ( ), , , , java, ?
, .
(, ) , .

,

module Devise
  module Models
     module Authenticatable
     extend ActiveSupport::Concern
     ...
  end
end

: Authenticatable, , . , , , . ?

+4
2

, Ruby . :

Module B; end
class A
  include B
end
A.ancestors # => A, B, etc.

, B :

Module C
  def a_module_method; end
end
Module B; extend C; end

Ruby a_module_method . , :

A.a_module_method

, . .

+2

Re: 1

. , , . , , ..

,

  • .
  • / / . Ruby . , / / .

, /, .


Re: 2

( , , BasicObject), , . , . , , , .


Ruby, Ruby Module

+2

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


All Articles