Jon Lebensold
Jon Lebensold

Reputation: 349

Overloading a method in an ActiveSupport::Concern

How can I have a concern that I've written like this:

module Concerns
  module MyConcern
    extend ActiveSupport::Concern
    ...
    def my_concern_magic(arg0,arg1)
      #exciting stuff here
    end
  end 
end 

that is included in a model that overloads my_concern_magic? E.g.

class User
  include Concerns::MyConcern
  ...
  def my_concern_magic(arg0)
    arg1 = [1,2,3]
    my_concern_magic(arg0,arg1)
  end
end

Upvotes: 9

Views: 2810

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 96914

Since including a module inserts it into the ancestor chain, you can just call super:

class User
  include Concerns::MyConcern

  def my_concern_magic(arg0)
    arg1 = [1, 2, 3]
    super(arg0, arg1)
  end
end

Upvotes: 14

Related Questions