DEV Community

Rossella Ferrandino
Rossella Ferrandino

Posted on

Learning Ruby: naming conventions

Ruby has specific naming conventions that make it easier to write and read code. I would like to summarize them here in a cheatsheet format that is easier to refer to.

snake_case:

  • files
  • variables
  • methods
#files
my_first_ruby_file.rb

#variables
programming_language = "Ruby"

#methods
def make_an_example
  #do stuff
end
Enter fullscreen mode Exit fullscreen mode

UPPERCASE:

  • constant variables

Constant variables represent values that will not change during your Ruby program.

ID = AB123456
FAVORITE_FOOD = "Pizza"
Enter fullscreen mode Exit fullscreen mode

CamelCase:

  • classes
class Person
end

class Movie
end
Enter fullscreen mode Exit fullscreen mode

Additional note

When working with do/end blocks, it is preferable to use { } when the code can fit in a single line

characters = ["Eleven", "Mike", "Dustin", "Lucas", "Will"]
characters.each do |character|
  puts character
end

characters.each { |character| puts character }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)