【发布时间】:2014-01-17 11:42:17
【问题描述】:
我知道我可以覆盖或添加到已经存在的类,但我想向现有模块(在 gem 中)添加额外的类,以便在调用它时保持不变。因为我虽然当rails加载lib时。他们应该认识到这一点。
请参阅以下示例。我想将 NotAcceptableHttpResponseError 添加到同一个 HttpService 模块中
示例 模块 HttpService(在 gem 中)只有相当数量的异常类,我想为其他人添加一些自定义的类
config/application.rb
config.autoload_paths += %W(#{config.root}/lib)
在 gem/exceptions.rb 中
module HttpService
class BadHttpResponseError
xxx
xxx
end
在 lib/http_service/exceptions.rb 中
module HttpService
class NotAcceptableHttpResponseError
xxx
xxx
end
end
错误
NameError(uninitialized constant HttpServices::NotAcceptableHttpResponseError)
【问题讨论】:
标签: ruby-on-rails ruby