Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should one use dashes or underscores when naming a gem with more than one word?

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

  • 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 is the name of the gem, and the base *.rb file is called lib/acts-as-taggable-on.rb (hyphens)

  • 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?

like image 530
dan Avatar asked Jan 14 '11 03:01

dan


People also ask

Should I use dashes or underscores?

Guidelines for names Make file and directory names lowercase. Use hyphens, not underscores, to separate words—for example, query-data. html .

Should I use underscores?

There are really only two non-alphanumeric characters that you should use in naming your files: dashes and underscores. Dashes are preferred for a couple of reasons. They are visible when an underlined hyperlink is rendered on the screen - underscores get covered by the underline.

Should I use underscore in filenames?

Avoid using spaces and underscores in file names. Some software packages have difficulty recognising file names with spaces; this can be a particular difficulty for files when they are published on an external website.


2 Answers

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

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.

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.

like image 128
Andrew Grimm Avatar answered Sep 22 '22 12:09

Andrew Grimm


Following the advice here, here is a table of how things would break down:

Gem name Require statement Main class or module
fancy_require require 'fancy_require' FancyRequire
ruby_parser require 'ruby_parser' RubyParser
net-http-persistent require 'net/http/persistent' Net::HTTP::Persistent
rdoc-data require 'rdoc/data' RDoc::Data
autotest-growl require 'autotest/growl' Autotest::Growl
net-http-digest_auth require 'net/http/digest_auth' Net::HTTP::DigestAuth
like image 22
user160917 Avatar answered Sep 21 '22 12:09

user160917