How to name variables with numbers in Ruby

What is the right convention in Ruby to name the variables if the number is the last character?

my_awesome_variable_1 or my_awesome_variable1

a_1 or a1

firs_1? or firs1?

foo_1_000_000 or foo1000000

Sub-question: what about acronyms?

  • for variables

foo_RTFM or foo_rtfm

  • and for classes/moudles

FooRTFM or FooRtfm

EDIT: it looks like there is no such a convention in Ruby, so let me ask you what you use.

a_1 / a1


I suggest you don't use numbers in variable names.

If you have multiple things, simply use an Array:

thing = []
thing << "foo"
thing << "bar"
# or
thing = ["foo", "bar"]

While Ruby doesn't provide you with a strict style guide like Go does, there is an excellent Style Guide by Bozhidar Batsov

To answer most of your question:

Use snake_case for symbols, methods and variables


Use CamelCase for classes and modules. (Keep acronyms like HTTP, RFC, XML uppercase.)

(This CAN lead to problems if you work with rails, but there is a simple solution.)

Need Your Help

Python - passing objects of different classes into functions

python class object dictionary

I'm having some trouble in python with classes and objects. I have two classes, and I instantiated an object of each. I'd like to pass those objects into a function when the user types a certain st...

How to combine text and variables in fastcgi_param?


tldr: how do I randomly mix text and variables in the value part of fastcgi_params? In particular adding spaces as text between variables, doesn't work with or without " or '.