Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Contact Class: Part 1 6:05
- Create a Contact Class 1 objective
- Contact Class: Part 2 4:04
- Write a Method 1 objective
- Phone Number Class 6:15
- Write a to_s Method 1 objective
- Address Class: Part 1 5:00
- Address Class: Part 2 3:44
- Initializing and Calling Methods 2 objectives
- Address Book Class 4:25
- Instance variable instantiation 2 objectives

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
With all of our supporting classes set up, we can define an `AddressBook` class to hold our program.
Code Samples
require "./contact"
class AddressBook
attr_reader :contacts
def initialize
@contacts = []
end
def print_contact_list
puts "Contact List"
contacts.each do |contact|
puts contact.to_s('last_first')
end
end
end
address_book = AddressBook.new
jason = Contact.new
jason.first_name = "Jason"
jason.last_name = "Seifer"
jason.add_phone_number("Home", "123-456-7890")
jason.add_phone_number("Work", "456-789-0123")
jason.add_address("Home", "123 Main St.", "", "Portland", "OR", "12345")
nick = Contact.new
nick.first_name = "Nick"
nick.last_name = "Pettit"
nick.add_phone_number("Home", "222-222-2222")
nick.add_address("Home", "222 Two Lane", "", "Portland", "OR", "12345")
address_book.contacts.push(jason)
address_book.contacts.push(nick)
address_book.print_contact_list
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Nafeez Quraishi
12,416 Points2 Answers
-
Jasmine Frantz
8,299 Points2 Answers
-
Sean Flanagan
33,236 Points0 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up