重载ActiveSupport :: Concern中的方法

时间:2012-12-28 22:04:06

标签: ruby-on-rails ruby overloading activesupport

我怎么能担心我这样写过:

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

包含在重载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 个答案:

答案 0 :(得分:11)

由于包含模块将其插入祖先链中,您只需拨打super

class User
  include Concerns::MyConcern

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