Improve the Behavior by Using a Routine
Learn how to code routines.
We'll cover the following...
Introducing a routine
Up to this point, we’ve been showing the number of letters by explicitly setting the display (by using puts "_ _ _ _ _"
). Since we’ve set the hidden_word
, the current game only offers one hidden word.
We will, of course, consider having other words. Therefore we must be able to show the number of letters depending on the word we hide. And we do this dynamically.
Let’s introduce a new concept offered by Ruby language called “function,” “method,” or “routine”. The name routine is the one that is best suited.
When we do something that we repeat over and over, we say that we accomplish a routine task. The task is broken down into a sequence of actions or operations that we perform in the same order. The programming languages allow defining a ...