Constants
How to create constants? (kinda)#
- Anything that starts with uppercase is a constant in Ruby.
- They are constants because the first letter is uppercase.
- A constant doesn’t require any special symbol or syntax to declare. You just need to make the first letter an uppercase letter.
- These are all valid constants:
Constants can change 🤷#
- Constants are mutable in ruby.
- Constants can changes 🤷... but you will get an warning:
- There is no way to prevent a constants from changing 😱
- Because variables in Ruby are not containers, they are simply pointers to objects. Or labels, if you prefer.
Can't defined constants inside a method:#
Class assigned to a constant#
- When you define a class, what you’re really doing is creating a Class object, which is assigned to a constant.
- The constant becomes the class name.
- No real constants in Ruby. 🤦