Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby gem naming conventions

I'm creating a ruby gem and I've noticed that there doesn't seem to be (to my knowledge) a naming convention for gems. For example, I've seen both:

gem 'foo-bar' gem 'foo_bar' 

Is there some kind of definitive guide/convention for the naming of ruby gems?

like image 332
Kyle Decot Avatar asked Jan 22 '12 04:01

Kyle Decot


People also ask

What is Gemname?

GEMNAME - name of the gem to print information about.

What are gem files in Ruby?

A Gemfile is a file that is created to describe the gem dependencies required to run a Ruby program. A Gemfile should always be placed in the root of the project directory.


1 Answers

The dashed version is for extensions on other frameworks, like rspec-rails and the underscore is for part of the normal gem name and should be camelcased in your classes.

So if you have a gem named foo_bar, the class/module should be named FooBar. If that gem should have a rails extension which ships as a different gem, it should be called foo_bar-rails and the module should be called FooBar::Rails and it should be required as require "foo_bar/rails"

This convention is also what Bundler tries to require.

Admittedly, this convention is not always followed. jquery_rails should actually be jquery-rails and factory_girl_rails should be called factory_girl-rails. But hey, not everything is perfect.

RubyGems convention docs:

  • Naming gems
  • Naming patterns
  • Make your own gem
like image 112
iain Avatar answered Sep 24 '22 04:09

iain