我想覆盖 marshal
方法,ActiveRecord
但不确定如何为类中的模块内的方法做
module ActiveRecord
class SessionStore < ActionDispatch::Session::AbstractStore
module ClassMethods
def marshal(data)
::Base64.encode64(Marshal.dump(data)) if data
end
end
end
end
我试过这个config/initializers/active_record.rb
ActiveRecord::SessionStore.class_eval do
ClassMethods.module_eval do
def marshal(data)
# Code
end
end
end
但它会引发错误
config/initializers/active_record.rb:2:in `block in <top (required)>': uninitialized constant ClassMethods (NameError)
编辑
我正在尝试覆盖config/initializers/active_record.rb
,不想编辑 gem 文件