如何在多个模块上使用相同的 class 名称?

How to use the same class name over multiple modules?

如何在多个模块上使用相同的 class 名称?

我有一个主ApplicationService

# /app/services/application_service.rb

class ApplicationService; end
# /app/services/processing/queue/application_service.rb

module Processing
  module Queue
    class ApplicationService < ApplicationService; end
  end
end
# /app/services/processing/callback/application_service.rb

module Processing
  module Callback
    class ApplicationService < ApplicationService; end
  end
end

如何让rails不迷茫,懂得使用/app/services/application_service.rb

我在 /app/services/processing/queue/ 中的所有服务都有 /app/services/processing/queue/application_service.rb 作为父级 class。

使用 FQN(完全限定名称)::ApplicationService 来引用您的顶级 class。

module Processing
  module Callback
    class ApplicationService < ::ApplicationService; end
  end
end