加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在ActiveSupport :: Concern中重载方法

发布时间:2020-12-16 19:21:15 所属栏目:百科 来源:网络整理
导读:我怎么能担心我这样写的: 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 .
我怎么能担心我这样写的:
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

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读