Split the Source Code

Make a separate file for word_info routine

Every time we make a change, the number of lines of code increases. We went from a few lines of code—only eight lines—to forty-five lines. The more the number of lines, the more challenging it gets to find where one or the other item is located. However, we already isolated a set of operations by grouping them in a routine.

One option that programming languages provide is to isolate the parts of the code in different files. This frees us from the need to keep in mind the dozens of lines written in other files so that we can focus on the file in which we are working.

Another advantage of isolating the parts of code in different files is that we can reuse the same code to do valuable things in other projects (other games, for instance).

We will move the word_info routine to a new file named word_info.rb.

Get hands-on with 1400+ tech skills courses.