Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Guided: Build a Library System with Ruby

In this Guided Code Lab, you will construct an object oriented "library system" with Ruby. You will design three core classes — Book, Borrower, and Library — to simulate fundamental library operations, such as adding books, checking them out, and returning them.

Lab platform
Lab Info
Level
Intermediate
Last updated
Aug 22, 2025
Duration
52m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Introduction

    In this Guided Code Lab, you will construct an object oriented "library system" with Ruby.

    You will design three core classes — Book, Borrower, and Library — to simulate fundamental library operations, such as adding books, checking them out, and returning them.

    Class Structures

    Book Class

    • The Book class will represent individual books. Each book will have attributes such as title, author, and available.

    Borrower Class

    • The Borrower class will represent people who come to borrow books. Each Borrower will have attributes like name and borrowed_books, which will hold a list of books currently borrowed by them.

    Library Class

    • The Library class will act as the main hub where the operations take place. This class will have attributes such as book_list (a list of all books in the library) and methods to add books, check out books to borrowers, and receive returned books.

    Interactions Between Objects

    As you develop these classes, you'll also implement methods that allow these objects to interact. For example, when a borrower checks out a book, the availability of the book changes, and the book gets added to the borrower's borrowed_books list. Similarly, when a book is returned, its availability changes again, and it gets removed from the borrower's list.

    When you are finished, click Run inside the Terminal to see the application's output.

    If you're ready to get started, click the arrow below.

  2. Challenge

    Creating a Book Class

    The Book class creates the books inside the library.

    Attributes:

    • title
    • author
    • availability

    Methods:

    • initialize

    All of your code will be written inside the book.rb file.

  3. Challenge

    Creating a Borrower Class

    The Borrower class keeps track of who borrowed what books.

    Attributes:

    • name
    • borrowed_books

    Let's get started!

    All of your code will be written inside the borrower.rb file.

  4. Challenge

    Creating a Library Class

    The Library class will let you keep track of the inventory and peform all of the typical tasks of a library such as add books, checkout books, return books, and see what books are available.

    Attributes:

    • inventory

    Methods:

    • initialize
    • add_book
    • checkout_book
    • return_book
    • list_available_books

    Let's get started!

    All of your code will be written inside the library.rb file.

  5. Challenge

    Library Methods

    Overview

    This section will cover the helper methods inside the Library class that give the app it's main functionality.

    Methods:

    • add_book
    • checkout_book
    • return_book
    • list_available_books

    Let's get started!

    All of your code will be written inside the library.rb file.

  6. Challenge

    Using the Library System

    If you're classes are complete, you can click Run in the Terminal to see the following output:

    The Great Gatsby has been checked out to John Doe.
    The Great Gatsby is not available.
    Available books:
    1984
    The Great Gatsby has been returned by John Doe.
    Available books:
    The Great Gatsby
    1984
    

    Feel free to experiment, add books, check them out, and use the methods from the Library class.

About the author

Danny Sullivan is a former special education teacher and professional baseball player that moved into software development in 2014. He’s experienced with Ruby, Python and JavaScript ecosystems, but enjoys Ruby most for its user friendliness and rapid prototyping capabilities.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight