Ruby 模块声明 [英] Ruby Module Declaration

查看:52
本文介绍了Ruby 模块声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做有什么区别吗

class Bus::Driver
end

module Bus
  class Driver
  end
end

如果不是,首选哪种语法?

If not, which syntax is preferred?

推荐答案

做 [...] 有什么区别吗?

Is there any difference between doing [...]?

唯一的区别是在class Bus::DriverBus模块必须已经定义,而相同并不代表第二个.

The only difference is that in class Bus::Driver the Bus module must be already defined, while the same does not stand for the second.

首选哪种语法?

这不是一个建设性的问题,但我个人更喜欢第二个,因为它明确指出 Bus 是一个模块,而第一个我第一眼看不到 Bus> 是一个模块或一个类.

This is not a constructive question but I personally prefer the second because it states explicitly that Bus is a module, while with the first I cannot see at first glance if Bus is a module or a class.

这篇关于Ruby 模块声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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