::(双冒号)在Ruby中是什么意思? [英] What does :: (double colon) mean in Ruby?

查看:112
本文介绍了::(双冒号)在Ruby中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

::在Ruby中是什么意思?例如. Foo::Bar.

What does :: mean in Ruby? E.g. Foo::Bar.

推荐答案

从镐头:

在方法调用中显式指定接收方时,可以使用句点(.)或两个冒号(::)将它与方法名称分隔.如果方法名称以大写字母开头,则这两种形式之间唯一的区别发生.在这种情况下,除非方法调用在括号之间包含参数列表,否则Ruby会假定receiver::Thing方法调用实际上是在访问接收器中的常量Thing的尝试.

When a receiver is explicitly specified in a method invocation, it may be separated from the method name using either a period (.) or two colons (::). The only difference between these two forms occurs if the method name starts with an uppercase letter. In this case, Ruby will assume that a receiver::Thing method call is actually an attempt to access a constant called Thing in the receiver unless the method invocation has a parameter list between parentheses.

这篇关于::(双冒号)在Ruby中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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