00:00
02:47
In this episode we talk about constants, and why the distinction between snake case and camel case is important in ruby.
Constants
In ruby constants are anything that start with capital letter. So inside of a class we can define a constant or even the naming of the class itself is a constant and starts with capital letters.
class Product
TYPES = ['game', 'food']
end
In this case we have a constant TYPES that holds the array with 2 values.
Snake Case / Camel Case
Having a clear distinction between snake case and camel case is important in ruby, this is because if we define something starting with a capital letter they will be regarded as 'constants', so if we're assigning something to a variable it's important to use snake case.
variables_are_snake_case = "yay"
def method_names_are_also_snake_case
puts "important distinction"
end
ConstantsAreCamelCase = "awesome"
class Animal
# defining classes are also done with Constants
end
That's all for this episode!