How to Name Gems

drbrain | Mon, 15 Nov 2010 22:12:20 GMT

Posted in

If you went to the first round of RubyConf lightning talks you saw me say this already, but I got enough applause that this needs wider dissemination.

Here is my STRONG recommendation on how to name gems:

Use underscores

This matches the file the user will require and makes it easier for the user to start using your gem. gem install my_gem will be loaded by require 'my_gem'.

Use dashes for extensions

If you're adding functionality to another gem use a dash. The dash is different-enough from an underscore to be noticeable. If you tilt the dash a bit it becomes a slash as well, making it easier for the user to know what to require. gem install net-http-persistent becomes require 'net/http/persistent'

Don't use UPPERCASE letters

OS X and Windows have case-insensitive filesystems by default. Users may mistakenly require files from a gem using uppercase letters which will be non-portable if they move it to a non-windows or OS X system. While this will mostly be a newbie mistake we don't need to be confusing them more than necessary. comments

Comments RSS FEED

If I am writing an extension for “ruby_parser” then would my gem name be the algorithmically correct “ruby_parser-my_extension” or the nicer looking “ruby-parser-my-extension”?

Dr Nic Williams said 13 minutes later

I would use ruby_parser-my_extension.

Any other extensions using the same name will be consistently grouped along with ruby_parser. Your extension would probably be loaded by require ‘ruby_parser/my_extension’, or at least live in a directory like that.

Eric Hodel said about 1 hour later

Why not have slashes in the name of a gem, and just call it ruby_parser/my_extension?

gem install ruby_parser/my_extension
and
require ‘ruby_parser/my_extension’

both seem totally reasonable.

BJ Clark said 1 day later

BJ, it’s good to have gem names be valid file names.

John Barnette said 1 day later

Spread the gospel man, spread it far and wide!

Rob Kaufman said 1 day later

As John said, gem names with slashes in them won’t work in every file system.

Github made – as a namespace separator a common feature in gem names that many have come to expect.

Eric Hodel said 1 day later

We use underscores in Ruby on Rails and dashes in Java pom’s.

stepan said 7 days later

Comments are disabled