Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
The Ruby Workshop

You're reading from   The Ruby Workshop Develop powerful applications by writing clean, expressive code with Ruby and Ruby on Rails

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher Packt
ISBN-13 9781838642365
Length 544 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Dániel Szabó Dániel Szabó
Author Profile Icon Dániel Szabó
Dániel Szabó
Akshat Paul Akshat Paul
Author Profile Icon Akshat Paul
Akshat Paul
Peter Philips Peter Philips
Author Profile Icon Peter Philips
Peter Philips
Cheyne Wallace Cheyne Wallace
Author Profile Icon Cheyne Wallace
Cheyne Wallace
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Writing and Running Ruby Programs 2. Ruby Data Types and Operations FREE CHAPTER 3. Program Flow Ruby Methods 5. Object-Oriented programming with Ruby 6. Modules and Mixins 7. Introduction to Ruby Gems 8. Debugging with Ruby 9. Ruby Beyond the Basics l 10. Ruby Beyond the Basics ll 11. Introduction to Ruby on Rails l 12. Introduction to Ruby on Rails ll Appendix

Service Objects

In previous sections, we learned how to install and include Ruby gems to extend the functionality of our application. We also learned how to interact with files and CSV data. We now know how to read, process, and output data to the screen or the filesystem.

This is useful functionality, although opening files and writing CSV data is something that we would generally consider to be a common functionality that is likely to be shared between classes and can also seem unrelated to the existing classes in our code base.

What do we mean by unrelated? Well, let's assume we have a User class and a Company class in our application. We want the ability to load user and company data and print it to the Terminal for both of these classes. So, where do we write the code for this functionality? In the User class? In the Company class? Or, in both classes?

Possible solutions to the common usage code issue are using modules, service classes, and class inheritance.

...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime