簡體   English   中英

如何在Rails中訪問ruby中的兩個相同的類

[英]How to access two same classes in ruby on rails

我在控制器中調用了名為Configuration的類。 而不是實例化我的Configuration類,它嘗試實例化ActiveSupport::Configurable::Configuration

如何訪問我的 Configuration類,命名為另一個相同庫的Configuration

class SampleController < ActionController::Base
  def m1
    cfg = Configuration.new
  end
end
class SampleController < ActionController::Base
  def m1
    cfg = ::Configuration.new
  end
end

不過,我建議您將自己的類放在自己的模塊中。

除了避免像這樣的類名沖突之外,它還提供了一個結構,您可以從中懸掛更多自己的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM