Owen_AR
Owen_AR

Reputation: 3027

Ruby naming conventions?

For instance, for constants, is it:

THIS_CONSTANT

This_Constant

ThisConstant

Or something else...?

In fact, is there any sort of (quasi|)official reference for this whole subject?

I'd also like to be able to quickly double check questions like:

and so on...

Upvotes: 49

Views: 80005

Answers (3)

user636044
user636044

Reputation:

The Ruby Style Guide is a public effort to recommend consistent conventions and best practices to Ruby developers. You should check it out.

Upvotes: 78

Purkhalo Alex
Purkhalo Alex

Reputation: 3627

In brief

The camel case for classes and modules definition we use CamelCase

The snake case for files, variables and methods: snake_case

Upvotes: 16

John Schmidt
John Schmidt

Reputation: 172

The syntax highlighting in your text editor can give you some good clues as you're learning a language and trying to develop an instinct for its conventions, enforced and otherwise. I use the Linux Gedit editor.

Yesterday I was pleasantly surprised to find that some of the conventions for commenting recommended by The Ruby Style Guide https://github.com/bbatsov/ruby-style-guide, such as # TODO and # FIXME, show up as bold face bright yellow. Constant names with ALL CAPS are bold cyan. Of course, different editors use different color schemes.

Upvotes: 1

Related Questions