Introduction
In the previous chapter, we studied the concept of arrays and hashes in Ruby. We also looked at different methods applied to arrays and hashes. In this chapter, we will be looking at how programs in Ruby are designed and used in applications.
Useful software programs are not simply a linear set of instructions; they make decisions about what code to run at any given time based on a set of conditions or criteria. Different programming languages have different types of program flow options. Two of the most common types of program flow options are conditionals and loops, which we will cover in this chapter.
Conditionals, also known as branches, are like a fork in the road. Do you turn left, or do you turn right? In the case of programming, for instance, you can decide what to do if a variable equals a value or is less than or greater than a certain value. Software simplifies the problem and makes the decision simply about truthiness: whether a condition is satisfied...