Eyal Bukchin
Eyal Bukchin

Reputation: 460

Extending ActiveSupport::Concern

I'm trying to extend an existing Concern in a different Rails project. This module exists in a gem I'm requiring:

module Foo
  extend ActiveSupport::Concern
  included do
    #some stuff
  end

  def method_a
  end
end

And then in my project:

module Foo
  extend ActiveSupport::Concern
  included do
    #some other stuff
  end

  def method_b
  end
end

Result is, objects including Foo only have method_b, and only run #some other stuff on inclusion. Is there any way for all code under included to run, and all methods to be added?

EDIT: Both the gem and the project are mine, and I'm not dead set on using ActiveSupport::Concern if there's a more fitting solution.

Upvotes: 4

Views: 1223

Answers (1)

rewritten
rewritten

Reputation: 16435

You shouldn't override or extend directly the concern. With a simple module it would be maybe useful, but concerns are set up to be explicitly extended:

module MyFoo
  extend ActiveSupport::Concern
  extend Foo

  included do
    #some other stuff
  end

  def method_b
  end
end

Upvotes: 6

Related Questions