Ruby-命名约定-类/模块名称中首字母缩写词的大写字母吗? [英] Ruby - Naming Convention - letter case for acronyms in class/module names?

查看:127
本文介绍了Ruby-命名约定-类/模块名称中首字母缩写词的大写字母吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个名为"SCM"的模块内创建一个表示"SVN"的类.但是我不知道在Ruby中使用首字母缩略词时的惯例是什么,并且除了首选驼峰式"之外,在Google中找不到任何相关内容.

I need to create a class that represent "SVN" inside a module called "SCM". But I don't know what is the convention when dealing with acronyms in Ruby, and could not find anything relevant in Google, except "Camel case is preferred".

我应该叫它SCM::SVN还是Scm::Svn?有约定吗?

Should I call it SCM::SVN or Scm::Svn? Is there a convention for this?

推荐答案

SCM::SVN对我来说看起来最好. Rails充满了ERB,ORM和 OMFGIMATEAPOT .更不用说像JSONSerializer之类的东西了. Ruby的来源也有很多首字母缩写词.对我来说,最明显的例子是YAML.正如我所看到的,标准是大写CamelCase字母,但通常不小写(尽管Rails对模型名称有意见).

SCM::SVN looks best to me. Rails is full of classes like ERB, ORM and OMFGIMATEAPOT. And that's not to mention things like JSONSerializer. Ruby's source has a bunch of acronyms, too. The most obvious example to me is YAML. The standard as I've seen it is to upcase letters for CamelCase but generally not to downcase them (although Rails has opinions on model names).

如果您有grep和源代码,则可以看到很多类似这样的示例

If you have grep and the source code you can see plenty of examples with something like

grep -r 'class [A-Z]\{3,\}' <path/to/source>
# or, if you only want acronyms and nothing like YAMLColumn:
grep -rw 'class [A-Z]\{3,\}' <path/to/source>

这篇关于Ruby-命名约定-类/模块名称中首字母缩写词的大写字母吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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