重构某些文件后,我收到了错误消息。当我打电话
@batch << Formatter.get(@fields)
它返回@fields
。当我尝试使用调试器进入Formatter.get
方法时,我发现它已被跳过。
我的目录结构如下:
lib / klass / formatter.rb包含:
require 'formatter/formatter'
require 'formatter/foo_formatter'
require 'formatter/bar_formatter'
module Klass
class Formatter
end
end
lib / klass / formatter / formatter.rb包含:
module Klass
class Formatter
attr_accessor :fields
def self.get fields
case fields[:field_id]
when "foo"; FooFormatter.new fields
when "bar"; BarFormatter.new fields
end
end
lib / klass / formatter / foo_formatter.rb包含:
module Klass
class FooFormatter < Formatter
答案 0 :(得分:1)
您需要更改lib / klass / formatter / formatter.rb的命名空间,使其读取
module Klass::Formatter
class Formatter
attr_accessor :fields
def self.get fields
case fields[:field_id]
when "foo"; FooFormatter.new fields
when "bar"; BarFormatter.new fields
end
end