module ActionController
module Filters
def self.included(base)
base.class_eval do
extend ClassMethods
include ActionController::Filters::InstanceMethods
end
end
module ClassMethods
def append_before_filter(*filters, &block)
filter_chain.append_filter_to_chain(filters, :before, &block)
end
alias :before_filter :append_before_filter
# ...
end
为什么要采用
base.class_eval do
extend ClassMethods
而不是
base.extend ClassMethods