在另一个模块内调用模块会给出错误的命名空间

时间:2015-01-27 12:56:41

标签: ruby-on-rails

我有一个像这样的简单模块:

module Oauth
  class Something
     def self.do_stuff
        Oauth2::Client.new(...)
     end
  end
end

但是当我调用do_stuff方法时,我收到的错误是: "uninitialized constant Oauth::Something::Oauth2"

我是否需要做任何特定的事情才能在模块中使用Oauth2 :: Client?

1 个答案:

答案 0 :(得分:4)

如果Oauth2位于根命名空间中,则可以通过使用::预先挂起来强制常量查找从顶部开始。

module Oauth
  class Something
     def self.do_stuff
        ::Oauth2::Client.new(...)
     end
  end
end
相关问题