帮助尝试为美国的县信息编写内部gem /插件。我希望按县组织事情,因为每个县都需要独特的信息解析。
目录结构类似于:
我希望能够通过CountyInfo::State::FL::Dade.hello
最初认为下面会有效:
require 'county_info/state'
class CountyInfo
end
Dir[[File.dirname(__FILE__), '/*/*.rb'].join].each{ |f| require f } # loads all folders with the names of each state
class State < CountyInfo
end
Dir[[File.dirname(__FILE__), '/counties/*.rb'].join] .each{ |f| require f } # loads all the counties for this each state
class FL < State
end
class Dade < FL
def hello
return "hello I am florida"
end
end
但是在启动应用时不断出错:
../app_name/lib/county_info/fl/counties/dade.rb:3:in `<top (required)>': uninitialized constant FL (NameError)
答案 0 :(得分:0)
仅仅因为FL
继承自State
,这并不意味着它是该类的一部分或在该命名空间内。
您应该可以致电Dade.new.hello
如果要将它们放在该命名空间层次结构中,您希望将它们嵌套
class CountyInfo
class State
class FL
class Dade
def hello
"hello I am florida"
end
end
end
end
end