Standard Ruby File Naming Conventions

For a file containing this class, SomeCoolClass, what will be the correct or standard file name?

  1. somecoolclass.rb
  2. some_cool_class.rb
  3. some-cool-class.rb
  4. SomeCoolClass.rb

or any other option?

I noticed that Ruby stdlib uses versions 1, 2, and 3.

+41
ruby file conventions naming-conventions
Oct 21 '08 at 9:44
source share
4 answers

With Ruby (i.e., not Rails), naming is just a convention. Rails required. Here says lowercasenounderscore.rb - this is a Ruby convention.

Choose either which convention is ever more common or which one you like more. The most important thing is to be consistent in the project .

+35
Oct 21 '08 at 10:25
source share

I would recommend lowercase characters with underscores (number 2 in your question). It is true that this naming scheme is a convention in Rails and is not needed in projects without Rails. However, I still adhere to the Rails convention because most Ruby programmers probably use Ruby exclusively for Rails.

+7
Oct 21 '08 at 11:07
source share

I personally believe that a hyphen as a word separator makes it as readable and typical as possible, so I recommend it where possible (in some contexts, a hyphen cannot be used, for example, in identifiers in most languages). It is important to keep in mind that the scheme you choose will be relevant to the requirement that users will use with your library, and you want to avoid using a different gem name than the library name .

poorly
 # gem install my_cool_lib require 'my-cool-lib' # gem install MyCoolLib require 'my_cool_lib' 
Good
 # gem install my_cool_lib require 'my_cool_lib' # gem install my-cool-lib require 'my-cool-lib' 

Unfortunately, a small part of the libraries violates this simple usability rule. Do not be one of these libraries. :)

+4
Oct 21 '08 at 14:53
source share
 my-proj β”œβ”€β”€ README β”œβ”€β”€ lib β”‚  └── some_cool_class.rb └── test └── some_cool_class_test.rb 
+3
Mar 05 '13 at 11:11
source share



All Articles