Dividing Code into Multiple Files
In the previous chapter, in order to test the main logic of our task-management app todo, we created the file lib/todo/task.rb, created a class Task that was inside the module Todo, and put some logic into the add_task method. We glossed over the reasons for this, but what we did was a standard way of organizing code in Ruby. This section will explain the how and why of code organization.
You might wonder why we should even bother storing our code in multiple files; it does add a certain amount of complexity to our application because code is no longer in one place. Keeping the code all in our executable carries complexity as well. In the previous chapter, we saw that we couldn’t unit test code that was stored ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access