Simple Contact Book with YAML Storage
Build a contact book that runs in the terminal, written in Ruby. You can add contacts with a name, phone number and email, list them in alphabetical order, search by name, edit a contact, and delete one after confirming. Everything is saved in a YAML file, a human-readable format you can open and read yourself, so your contacts are still there the next time you run the program. It's a great first Ruby project: you'll learn classes and methods, arrays and hashes, reading and writing files with Ruby's YAML library, checking user input, and organizing a small program so it's easy to test.
- Estimate
- ~8h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
YAML
Project roadmap
- 01
Set up the project and the Contact class
~1hCreate a project folder with lib/contact.rb, lib/contact_book.rb and bin/contacts. Write a Contact class with name, phone and email, and a valid? method that checks the name isn't empty, the phone contains only digits, spaces, + and - (at least 7 digits), and the email looks like something@something.something. Done when: creating valid and invalid contacts in irb gives the right valid? result.
- 02
Save and load contacts with YAML
~1.5hIn ContactBook, write load and save methods that read and write contacts.yml with Ruby's YAML library. Store contacts as plain hashes (name, phone, email), not Ruby objects, and load them with YAML.safe_load. If the file doesn't exist yet, start with an empty list; if it's corrupted, show a clear message instead of crashing. Done when: saved contacts are loaded correctly the next time the program runs.
- 03
Add and list contacts
~1.5hMake bin/contacts accept commands: add asks for the name, phone and email one at a time, validates them (asking again when a value is invalid), rejects a duplicate name and saves; list prints every contact sorted by name in aligned columns, or a message when the book is empty. Done when: adding a few contacts and listing them shows them sorted and neatly aligned.
- 04
Search and edit
~1.5hAdd search TEXT, which lists contacts whose name contains the text, ignoring upper and lower case. Add edit NAME, which shows the current values and lets the user change each field, where pressing Enter keeps the current value; validate the new values before saving. Show a clear message when no contact matches. Done when: searching finds partial matches, and editing updates only the changed fields.
- 05
Delete with confirmation
~1hAdd delete NAME, which shows the contact and asks Are you sure? (y/n); only y deletes it and saves the file. Print a message when the name doesn't exist. Add a help command that lists every command with an example. Done when: answering n keeps the contact, and y removes it from contacts.yml.
- 06
Write tests
~1.5hWrite tests with minitest for Contact#valid?, and for ContactBook using a temporary YAML file: adding, rejecting duplicates, searching, editing, deleting, and loading a missing or corrupted file. Add a Rakefile so rake test runs them. Done when: rake test passes.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack