模块的included方法会在其他的类或模块把这个模块混入他们自己里面时被调用,调用时传入的参数为混入模块的模块或类,如下代码
module A
def A.included(mod)
puts "#{self} is included in #{mod}"
end
end
module B
include A
end
当B混入A时,此时A的included方法会被调用,通常我们见到的为类设置他的实例方法和类方法的代码如下
module A
def A.included(mod)
def mod.method
puts "this is the class method"
end
end
def method
puts "this is the instance method"
end
end
class B
include A
end
b=B.new
b.method
B.method
输出结果为:
this is the instance method
this is the class method
当B混入A时,A.included方法被调用,参数为B,该方法中设置了B的method方法,而随着B混入A,A中的实例方法method也作为了B中的实例方法。从而实现了为B同时设置实例方法和类方法
分享到:
相关推荐
It included: Vehicle Packaging, H-Point Design Tool, 2D Manikin, Seat Lines, Seat Belt Anchorage Hand Reach, Eyellipse, Instrument Panel Visibility, Windshield Vision Zones, Direct Field of View, A ...
rollup.js 是下一代的 JavaScript 模块化工具,使用 ES2015 模块编写你的应用或者库,可以高效的绑定他们成为单个文件,在浏览器或者 Node.js 中使用,甚至是一些高级特性的绑定,比如 bindings 和 cycles。...
配置caffe时,在make时候把报错(fatal error: glog/logging.h: No such file or directory),可下载安装此模块
disc, 可视化browserify项目捆绑包的模块树并跟踪膨胀 光盘 Disc是分析 browserify 项目包的MODULE 树的工具。 它特别适用于捕捉大型和/或者重复的模块,这可以能会...在github页面的演示included是在自己的browseri
用单一的文档来源将这些库组织成模块的层次结构; 和为原本独立的库提供一致的API。建筑电池要求您将需要以下库: > = 3.12.1 > = 1.5.3 GNU make 来构建和运行测试(可选) > = 2.0.1以构建和运行测试(可选) 来...
jcss.included.inc.js 为一个叫included的引用 (inc)模块 jcss.css.ext.js 为一个叫css的拓展(ext)模块 注: 目前已有模块命名如下(其实刚才也说了) min ---------------- 最小核心 -------------整个框架的...
For most people, me included, these concepts are new, so this book teaches them from the ground up. It goes all the way from the motivation and basics to advanced features. More than that, it also ...
这是此类模块的示例: module M extend ActiveSupport :: Concern included do # @!method disabled # @!scope class # @return [Collection] Return a scope to get all disabled records scope :disabled , -> { ...
: "/node_modules/vue/dist/vue.esm.js" ,// Size of module"size" : "326.4 kB" ,// Size savings if de-duped"potential-size-savings" : "979.2 kB" ,// Chunks the module is duplicated in"included-...
Which mainly included database creation and maintenance, and front-end application development aspects. The former required strong data consistency and integrity of data, good safety database. For ...
100Base-T1车载以太网EMC测试模块,本模块可以直接放在EMC Chamber中,通过光纤转出,使用方便有效; 100BASE-T1 MEDIACONVERTER_EMC SET from Technica Engineering is the first commercial tool for EMC ...
virtkey这个库,这个库可以在linux 中模拟键盘按键
模块安装 参考官方文档安装 pip install PyExecJS ... Apple JavaScriptCore – Included with Mac OS X [removed]windows自带JS解释器,IE浏览器 SlimerJS 注:对于PyV8模块目前google上只提供了支持Pytho
本着“batteries included”的精神,标准库被按照用途组织,并且辅以简单、直观的示例。清晰的写作风格使得阅读本书成为一种乐趣。 --jeffery d. collins, development lead, 微软公司 当python程序员在回忆或解释...
本着“batteries included”的精神,标准库被按照用途组织,并且辅以简单、直观的示例。清晰的写作风格使得阅读本书成为一种乐趣。 --jeffery d. collins, development lead, 微软公司 当python程序员在回忆或解释...
本着“batteries included”的精神,标准库被按照用途组织,并且辅以简单、直观的示例。清晰的写作风格使得阅读本书成为一种乐趣。 --jeffery d. collins, development lead, 微软公司 当python程序员在回忆或解释...
Redis间隔模块 指令 间隔的语法: double ::= "-"(0-9)+*("." (0-9)+)? interval ::= ("[" | "]") (double | "-inf") "," (double | "+inf") ("[" | "]") Examples : [1,10] // between 1 included and 10 included...
超级模块1.4.1 (注意:尽管有高级版本号,但是super_module的想法是高度试验性的,并且在很大程度上依赖于元编程,因此,除非您确实需要它,否则在足够的情况下始终喜欢使用纯Ruby模块) 使开发人员即使想要继承...
GD32F103例程,包含驱动和每个模块的例程。
这个人偶模块设置了一个氧化车间,包括mysql服务器,apache和php。 特征 - MySQL Server installation/setup - PHP installation/setup - Apache installation/setup - Zend Guard installation/setup For the oxid...