Ruby naming conventions

naming-conventionsruby

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:

  • What naming patterns are enforced by Ruby itself (eg, Constants must start with a capital, right?) and which are simply conventions (method_names should be in snake case, right?)?

  • Are there any conventions for how to write a reminder of what class a variable is supposed to be into its name? ("Hungarian notation" or whatever… I mean, I kinda got the impression that if you ever feel the need to use it in Ruby code, you're Doing It Wrong, but regardless, is there a convention?)

and so on…

Best Answer

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

Related Topic