是否可以ActiveSupport::Callbacks
在类方法上使用?更具体地说,在下面的模块中,你会在哪里include ActiveSupport::Callbacks
创建define_callbacks
和run_callbacks
共享相同的状态?
module Handler
extend ActiveSupport::Concern
# If you put it here, define_callbacks is defined but run_callbacks is not
# include ActiveSupport::Callbacks
included do
class_eval do
define_callbacks :handle
end
end
module ClassMethods
# If you put it here, run_callbacks is defined but define_callbacks is not
# include ActiveSupport::Callbacks
def handle(task)
run_callbacks :handle do
p task
end
end
end
end
class HandlerExample
include Handler
end
更新
如果有可能,但我无法确定,那肯定不是ActiveSupport::Callbacks
为它设计的。最好在#handle
.