Obromios
Obromios

Reputation: 16383

Convention for capitalising the first letter of a Ruby on Rails file?

Some standard Ruby on Rails files have the first letter capitalised, e.g. Gemfile, Gemfile.lock, and Guardfile. Is there a convention in regard to this, or can I do this for any file I consider it important?

Upvotes: 0

Views: 101

Answers (1)

Aetherus
Aetherus

Reputation: 8888

Capitalized files are not Rails application source files, they are files required by some tools. for example, Gemfile and Gemfile.lock are for bundler, and Guardfile is for guard. None of these tools is shipped with Rails, and all of them can be used without Rails.

You have to stick to Rails conventions, because Rails conventions are not only conventions, they have some performance concerns.

For example, Rails forces you to put your model MyModel in the file app/models/my_model.rb. Rails will not load this file until this class is used. Rails assume that the class MyModel is defined in a file named my_model.rb, and is located in one of some special directories called autoload_paths, so Rails searches these directories for this specific file and loads it. If no such file, or there's no class MyModel defined in that file, then an error will be raised. Using this lazy loading mechanism, Rails can keep those never used (perhaps legacy) classes from being loaded into memory.

Upvotes: 1

Related Questions