Ruby中的"include"和"prepend"有什么区别? [英] What is the difference between 'include' and 'prepend' in Ruby?

查看:167
本文介绍了Ruby中的"include"和"prepend"有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模块

Module#append_features(mod)→mod =>当此模块包含在另一个模块中时,Ruby会在此模块中调用append_features,并将其传递给mod中的接收模块. Ruby的默认实现是 添加 (如果尚未将该模块的常量,方法和模块变量添加到mod或它的祖先之一).

Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors.

Module#prepend_features(mod)→mod =>当此模块附加在另一个模块中时,Ruby会在此模块中调用prepend_features,并将其传递给mod中的接收模块. Ruby的默认实现是 要覆盖 (如果尚未将此模块添加到mod或其祖先之一),以将该模块的常量,方法和模块变量进行修改.

Module#prepend_features(mod) → mod => When this module is prepended in another, Ruby calls prepend_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to overlay the constants, methods, and module variables of this module to mod if this module has not already been added to mod or one of its ancestors.

任何人都可以帮助我理解以下问题:

Can anyone help me to understand the below questions:

  • 除了默认设置外,Module的哪些功能还定义为appendprepend?

  • What more features of Module are defined as append and prepend except those default?

它们在功能上有何不同?

How they differ functionally?

何时使用append_features和何时使用prepend_features?

上述两条粗线之间有什么区别?

what is the difference between two bold lines as above?

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆