【发布时间】:2017-01-03 02:29:39
【问题描述】:
我正在勾勒 CsvVerify 模块的工作原理。有没有办法不污染将包含带有实例变量的模块的类
Idea 的灵感来自 virtus,如下所示:
employee_csv_importer.rb(使用模块)
class EmployeeCsvImporter
include CsvVerify
headers 'ID', 'First Name', 'Last Name', 'Title or Department',
'Age', 'Native Language', 'Fluent in English?'
end
csv_verify.rb
module CsvVerify
puts "included"
def headers(*names)
@config = Config.new
end
end
config.rb
module CsvVerify
class Config
end
end
那么我该如何重新组织它以避免@config 污染EmployeeCsvImporter?
PS。
为什么现在这甚至不起作用?
为什么我从运行 employee_csv_importer.rb 得到这个输出?
included
/data/gems/csv_verify/examples/1_employees.rb:6:in `<class:EmployeeCsvImporter>':
undefined method `headers' for EmployeeCsvImporter:Class (NoMethodError)
【问题讨论】:
标签: ruby module architecture instance-variables