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
UPPERCASE:
- constant variables
Constant variables represent values that will not change during your Ruby program.
ID = AB123456
FAVORITE_FOOD = "Pizza"
CamelCase:
- classes
class Person
end
class Movie
end
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 }
Top comments (0)