Skip to content
Switch branches/tags
This branch is 23 commits ahead, 7 commits behind CraftAcademy/library-challenge:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Library Challenge

Week 1 Ruby challenge


The code creates a Library class that contains a list of books read from an .yml file. The Library includes functions to add new books, checkout and return books.


  • Start irb in the terminal and load ./lib/library.rb and ./lib/person.rb
  • create a new library, add the library name as an argument:
 library1 ='library_name')

this will create the file library_name_data.yml in the main folder. And will initiate the library with five basic books.

  • The library books can be listed any time using the command:
puts library1.books

the result is an array of books, where each book is a hash that contains the book ID, title, author. In addition information about the availability of the book available, the name of person whom checked it out person and the date it should be returned return_date.

  • create a new person, add name (string) and personnummer (integer) as arguments:
person1 =, personnummer)

the person will have a name, a personnummer and the list of books borrowed form a library. When a new person is created the books are an empty array.

  • The person books can be listed any time using the command:
puts person1.books

the list shows the books titles, authors and return dates.

  • A person can check the list of available books in library using:
puts library1.books_available

this will lest the books available only

  • A person can check out a book from library by calling the Library method .checkout and passing argument of book id (integer) and person (object) borrowing the book:
library1.checkout(id, person)

this will set a return date of 30 days from today, and then update the books in the library and the person objects.

  • A person can return a book to library in similar method to checkout:
library1.return(id, person)

this will update both library and person objects.

  • A person can check the return date of unavailable book by ID using the method .return_date
  • A librarian can add books to the library collection using the method .add_book by passing the arguments of the new book title (string) and author (string) as follow:
library1.add_book(boo_title, book_author)

this will automatically create and ID for the book and add it to the collection and write it to the .yml file.

  • Error messages show in cases where a person try return an already returned book, or checkout an unavailable book, etc...
  • Please note thats the second book in the initial books ID = 2 is already borrowed available = false for test purpose.


Week 1 Ruby challenge






No releases published


No packages published