ruby 来自https://stackoverflow.com/questions/151505/difference-between-a-class-and-a-module

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 来自https://stackoverflow.com/questions/151505/difference-between-a-class-and-a-module相关的知识,希望对你有一定的参考价值。

╔═══════════════╦═══════════════════════════╦═════════════════════════════════╗
║               ║ class                     ║ module                          ║
╠═══════════════╬═══════════════════════════╬═════════════════════════════════╣
║ instantiation ║ can be instantiated       ║ can *not* be instantiated       ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ usage         ║ object creation           ║ mixin facility. provide         ║
║               ║                           ║   a namespace.                  ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ superclass    ║ module                    ║ object                          ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ methods       ║ class methods and         ║ module methods and              ║
║               ║   instance methods        ║   instance methods              ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ inheritance   ║ inherits behaviour and can║ No inheritance                  ║
║               ║   be base for inheritance ║                                 ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ inclusion     ║ cannot be included        ║ can be included in classes and  ║
║               ║                           ║   modules by using the include  ║
║               ║                           ║   command (includes all         ║
║               ║                           ║   instance methods as instance  ║
║               ║                           ║   methods in a class/module)    ║
╟───────────────╫───────────────────────────╫─────────────────────────────────╢
║ extension     ║ can not extend with       ║ module can extend instance by   ║
║               ║   extend command          ║   using extend command (extends ║
║               ║   (only with inheritance) ║   given instance with singleton ║
║               ║                           ║   methods from module)          ║
╚═══════════════╩═══════════════════════════╩═════════════════════════════════╝

以上是关于ruby 来自https://stackoverflow.com/questions/151505/difference-between-a-class-and-a-module的主要内容,如果未能解决你的问题,请参考以下文章

ruby 优化和缩小您的GIT存储库(Ruby脚本)。来自Jeff Smith @ rallydev.com。

使用来自 GitLab 的私有 gem 构建一个 Ruby 项目

ruby 来自Denys的数字任务

在 Ruby 中解析来自 Eventbrite API 的 JSON 响应

ruby 来自https://stackoverflow.com/questions/2505067/class-self-idiom-in-ruby

ruby 来自http://culttt.com/2015/07/08/working-with-mixins-in-ruby/