In this section, we are going to talk about conditionals in Ruby. This is a very important component of learning how to code, since conditionals allow our programs to make decisions based on varying data.
The conditionals guide
Real-world use of conditionals
Imagine that you're building a self-driving car. Your car would have sensors providing information such as GPS coordinates, the location and speed of the vehicles around the car, and the list goes on and on.
All of this data is great; however, how can we use it to make sure our car functions properly? Our program could follow a set of rules: the following are a few basic ones:
- If the speed limit is 40 MPH, ensure to match this speed
- If there is an accident in front...