A pattern you see around in Rails 3 source code is
module Foo extend ActiveSupport::Concern # ... end
- solves a problem of module dependencies piling up on the host, and
- provides a pattern for extending the host.
Piling up dependencies becomes a problem when you have a module
A and module
B uses methods provided by
A at include time.
Usually, host class
C needs to include module
A before module
that needed methods are available at include time, i.e. piling up dependencies.
ActiveSupport::Concern you can include
B and just
B to host
module A extend ActiveSupport::Concern # ... end module B extend ActiveSupport::Concern include A included do # use methods provided by A end end class C include B end
A concern module has a modified
Module#included which can be passed a block
to be evaluated. It also automatically extends its
and includes its
InstanceMethods module to host, if present.
See also documentation in the source code.