####I. Class, Module names
Class and Module names in Ruby should be properly formatted using CamelCase.
Capital Letters must be used to separate words.
Names should be as descriptive as possible.
Good examples:
class Invoice
class InvoiceService
module OrderHelper
Bad examples:
class invoice
module order_helper
class invoiceService
module orderhelper
####II. Constants
Constants in Ruby must be in UPPER_SNAKE_CASE.
Underscores must be used to separate words.
A good example:
SNS_MAPPING
A bad example:
SNSMAPPING
####III. Variables
All variables in Ruby must be in lower_snake_case.
Underscores must be used to separate words.
A good example:
sns_mapping
A bad example:
snsmapping
1. Global variables
Global variable names start with “$”.
Global variables are available throughout the whole Ruby application. So be careful when using global variables!!!
For example: $months_in_year
2. Class variables
Class variables names start with “@@”.
When creating a class variable, all instances of the same class in a Ruby application will share the new class variables. Likewise, if a change is made to a class variable, all other instances will see the change too.
3. Instance variables
Instance variables names start with “@”.
Think about instance variables as places to hold state of specific instances. As a rule of thumb, do not use instance variables as a mean to communicate data between methods within an instance, although you can do so. A better way to communicate data between methods is to pass them via parameters (unless data you want to communicate is really a state of an instance).
4. Local variables
Local variables' names must be a simple snake_case_string.
####IV. Method names
All methods in Ruby must be in lower_snake_case.
Underscores must be used to separate words.
Good examples:
parse_json_data
publish_message
Bad examples:
parseJsonData
parseJSONData
publishMessage
publishmessage
####V. File names
All Ruby filenames must properly be named using snake_case.
For example:
application.rb
application_controller.rb
Never use any other conventions in Ruby. The proper Ruby naming conventions always uses underscore to separate words.
Example of bad names:
Application.rb
ApplicationController.rb
applicationController.rb
applicationcontroller.rb
####VI. Meaningful names
One should never use one-character names. Do not name any of your things, no matter however trivial, with only one character..
For example : a, h, e are bad names..
All names must reflect their purposes and functionalities.
Bad examples:
text_file_1
text_file_2
get_data(p)
Good examples:
input_text_file
output_text_file
get_json_data(params)
At the same time, do not write too long a name.
It is a good practice to use the names to communicate what the things are.
For example: If you want to store a filename in a variable, calling it “input_filename” is better than calling it “input_file”.