2015-06-01 148 views
0

其实我正在试验ruby-lint和ruboto来改进我的代码。红宝石皮棉说:未定义常量ParseConfig

"get.rb: error: line 89, column 14: undefined constant ParseConfig"

在那个地方,我有标记代码:

require 'parseconfig' 
module PublicanCreatorsGet 
def self.config 
    home = Dir.home 
    config = ParseConfig.new("#{home}/.publicancreators.cfg") <------- 
end 
end 

但是是什么让这一个常数?我以为他们已经过了。

+0

错误真的意味着该类没有被发现在继错误。类名在技术上是常数。按照红宝石惯例,常量必须用大写字母开头,不一定全是资本;类和模块并不全是上限。 http://rubylearning.com/satishtalim/ruby_constants.html –

+0

非常感谢您澄清:-) –

+0

我不能重复这个问题?如果我需要'parseconfig',我可以毫无问题地访问顶级常量'ParseConfig'。 – engineersmnky

回答

0

名称以大写字母(A-Z)开头的变量是常量。

0

红宝石治疗类名作为常量,如果你真的想解决你可以试着模块

require 'parseconfig' 

module PublicanCreatorsGet 
    include ParseConfig 

    def self.config 
     home = Dir.home 
     config = ParseConfig.new("#{home}/.publicancreators.cfg") 
    end 
end 
+0

您的要求不正确'parseconfig'是一个宝石,并且需要'require'parseconfig'' – engineersmnky

+0

哦,我的不好,我好像是你写的一个类。我编辑了答案,这是否有助于你? –