ruby – 模块中的“self.included(base)”是什么意思?
发布时间:2020-12-17 01:31:19 所属栏目:百科 来源:网络整理
导读:我看到这种模式很多: module Article::Score def self.included(base) base.send :extend,ClassMethods base.send :include,InstanceMethods end module ClassMethods ... end module InstanceMethods ... endend 然后在文章模型中,我看到了这一点 class Ar
我看到这种模式很多:
module Article::Score def self.included(base) base.send :extend,ClassMethods base.send :include,InstanceMethods end module ClassMethods ... end module InstanceMethods ... end end 然后在文章模型中,我看到了这一点 class Article include Article::Score ... end 所以我的猜测是“base”可能是指文章类,我们只是包含实例方法并扩展类方法.但有人可以解释片段“self.included(base)”并概述那里发生了什么? 解决方法
包含模块时会调用self.included函数.它允许在基础(包含模块的位置)的上下文中执行方法.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ruby-on-rails – 如何在子目录中部署Rails 3.1应用程序
- c# – 在WinRT XAML中更改页面级别ListViewItem的选择颜色
- cocos2d-x调用scheduleUpdate()不执行update()方法的解决办
- swift – 像macOS上的Photos.app一样的macOS应用程序
- 浅析flex UI层实现
- c# – 为什么Assembly.GetType()找不到我的类?
- ruby-on-rails – 如何处理ActiveSupport :: JSON和JSON ge
- c# – 为什么listview触发事件表示添加后未选中已选中的项目
- 创建可被取消的默认事件处理器
- Reactor