对于 ruby 开发人员来说,这应该是一件容易的事。我正在玩一个 gem,我需要继承模块变量的帮助。代码应该比我说得更好:
module SomeModule
extend ActiveSupport::Concern
attr_accessor :bbonified
class Railtie < Rails::Railtie
initializer "some_module.study" do
Rails.application.eager_load!
# => I WANT TO ACCESS HERE
puts @bbonified
end
end
module ClassMethods
def bbonify(*columns)
# => WHAT I DEFINE HERE
@bbonified = columns
end
end
end
ActiveRecord::Base.send(:include, SomeModule)