I have a concern with an included block. In this example it sets a class instance variable.
require 'active_support/concern'
module Mod1
extend ActiveSupport::Concern
included do
p "#{self}: included Mod1"
@foo = "foo is set"
end
class_methods do
def foo
@foo
end
end
end
If I include it I get the method foo and the included variable is set.
class Parent
include Mod1
end
p Parent.foo # "Parent: included Mod1" "foo is set"
But if I subclass from Parent, I inherit the method foo, but the included block is not run.
class Subclass < Parent
end
p Subclass.foo # nil
Even if I include the module, the included block is not run. I expect because Subclass.include?(Mod1) is true.
class Subclass < Parent
include Mod1
end
p Subclass.foo # nil
p Subclass.include?(Mod1) # true
How do I write a concern such that its included block runs even on subclasses?