Module Baz
def foo
super
:baz
end
end
Class A
prepend Baz
def foo
:bar
end
end
A.new.foo //works fine
now if I transform my module to Concern module, it's not...
module BazConcern
extend ActiveSupport::Concern
included do
def foo
super
:baz
end
end
end
So how can we use prepend with ActiveSupport::Concern ? with ruby 2+
prepend
with ActiveSupport::Concern
(Rails 6.1+)Rails 6.1 added support of prepend
with ActiveSupport::Concern
.
Please, see the following example:
module Imposter
extend ActiveSupport::Concern
# Same as `included`, except only run when prepended.
prepended do
end
end
class Person
prepend Imposter
end
It is also worth to mention that concerning
is also updated:
class Person
concerning :Imposter, prepend: true do
end
end
Sources:
A link to the corresponding commit.
Rails allows a module with extend ActiveSupport::Concern to be prepended.
prepend and concerning docs.