重载ActiveSupport :: Concern中的方法

时间:2022-05-06 00:12:36

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.

包含在重载my_concern_magic的模型中?例如。

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

1 个解决方案

#1


11  

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

由于包含一个模块将其插入到祖先链中,您只需调用super:

class User
  include Concerns::MyConcern

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

#1


11  

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

由于包含一个模块将其插入到祖先链中,您只需调用super:

class User
  include Concerns::MyConcern

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