开发者

Ruby notation conventions

When writing about ruby code we use:

  • Dog to represent the dog class
  • #bark to represent an instan开发者_C百科ce method
  • .new or ::new to represent a class method

What's the convention for representing an instance of a class? dog would blend right in with the surrounding regular text.


That sounds about right. In Smalltalk, it is customary to use anArray, aString or aDog (even as parameter names in method declarations), which would translate to an_array, a_string or a_dog. However, that's not customary, and might look strange to an experienced Rubyist, who would expect to see ary, str and dog.

Note also that in general, the dot is only used in code examples for actual method calls. When talking about the method, always use # and :: for instance methods and singleton methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜