命名一个以上单词的宝石时,应该使用破折号或下划线吗? [英] Should one use dashes or underscores when naming a gem with more than one word?

查看:128
本文介绍了命名一个以上单词的宝石时,应该使用破折号或下划线吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当宝石名称包含多个单词时,我对宝石命名约定感到困惑.

I'm confused about what the gem naming convention is when the gem name has more than one word.

  • thinking-sphinx是宝石的名称,但是此宝石的基本* .rb文件是lib/thinking_sphinx.rb(下划线)

  • thinking-sphinx is the name of the gem, but the base *.rb file for this gem is lib/thinking_sphinx.rb (underscores)

acts-as-taggable-on是gem的名称,基本* .rb文件称为lib/acts-as-taggable-on.rb(连字符)

acts-as-taggable-on is the name of the gem, and the base *.rb file is called lib/acts-as-taggable-on.rb (hyphens)

factory_girl在gem名称和基本* .rb文件的名称中都使用下划线

factory_girl uses an underscore in both the gem name and in the name of the base *.rb file

使用下划线或连字符是否重要?这里有任何新兴共识吗?

Does it matter if one uses underscores or hyphens? Is any emerging consensus here?

推荐答案

Eric Hodel对此发表了一篇博客文章:

Eric Hodel has a blog post on this: A Project Naming Recommendation

Rails巩固了 将CamelCase类名称映射到 带下划线的文件名(类 IMAPProcesor在 imap_processor.rb).使用下划线 宝石名称使人们更容易 找出需要什么文件(相同 作为项目名称)或什么类 要在ri中查找的名称.

Rails solidified the convention of mapping CamelCase class names to underscored file names (class IMAPProcesor is defined in imap_processor.rb). Using underscored gem names makes it easy for people to figure out what file to require (same as the project name) or what class name to look for in ri.

如果我有一个插件gem或扩展名 我将添加子项目的名称 破折号.如果我想添加一个新的 大通银行imap_to_rss的处理程序 电子邮件,该宝石将被命名为 imap_to_rss-追逐.

If I have a plugin gem or an extension I’ll tack on the sub-project’s name with a dash. If I wanted to add a new handler for imap_to_rss for Chase bank email, the gem would be named imap_to_rss-chase.

这篇关于命名一个以上单词的宝石时,应该使用破折号或下划线吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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