Introduction

Welcome! In this lesson, we’ll explore creating a simple address book application using Ruby hashes. This exercise will strengthen your understanding of hashes in Ruby, specifically in adding, retrieving, and deleting entries.

By the end of this lesson, you’ll have a solid grasp of these fundamental operations and how they’re applied in practical programming tasks.

Introducing Methods to Implement

In this task, we’ll build three core methods to manage our address book:

  1. add_contact(name, phone_number): Adds a new contact. If the contact already exists, it returns false and does not overwrite the number; otherwise, it adds the contact and returns true.
  2. get_contact(name): Retrieves the phone number for a given name. If the contact does not exist, it returns nil.
  3. delete_contact(name): Deletes a contact with the specified name. Returns true if the contact was successfully deleted and false if the contact does not exist.
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal