之间的区别.和 # [英] Difference between . and #

查看:107
本文介绍了之间的区别.和 #的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Ruby 中,这两者之间的区别是什么(在代码中):

In Ruby what is the difference between those two (in code):

  • Class.method
  • Class#method

推荐答案

散列格式 (Class#method) 不是有效的 ruby​​,但在文档中用于描述实例方法.

The hash format (Class#method) is not valid ruby, but is used in documentation to describe an instance method.

通常使用双冒号(Class::method)记录类方法.

Class methods are typically documented using a double-colon (Class::method).

您将在 ruby​​ 文档中看到两者的示例(例如 http://www.ruby-doc.org/core-1.9.3/String.html)

You will see examples of both in the ruby docs (e.g. http://www.ruby-doc.org/core-1.9.3/String.html)

当实际调用一个类方法(Class.method)时,在代码中使用点格式,尽管我看到有些人(不幸地)将它与双冒号或散列互换使用文档.

The dot format is used in code when actually calling a class method (Class.method), though I have seen some people (unfortunately) use it interchangeably with either the double-colon or hash in documentation.

这篇关于之间的区别.和 #的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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