Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build an Address Book in Ruby Search Appending Contacts

I dont understand what it wants me to do

???

address_book.rb
contact = Contact.new
contact.first_name = "My"
contact.last_name = "Name"
address_book = AddressBook.new

1 Answer

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

Hi Victor,

I am not entirely familiar with the challenge and a bit more context would have helped, but I am guessing from your code snipped above, that you passed the first task and are wondering what the second part is asking you to do?

You have created an object in the first part and saved that object to the variable address_book. At creation it apparently initialised a contacts variable that contains an array. Your second task seems to be to append the contact variable from the top of the code to this array. To do that you have to access the array and then you can push the variable onto it:

contact = Contact.new
contact.first_name = "My"
contact.last_name = "Name"

address_book = AddressBook.new

address_book.contacts << contact

I would agree with you that without seeing the structure of the underlying class, it's not a lot of information to go on.

Matthew Wilkes
Matthew Wilkes
4,810 Points

This proved to be correct as well as:

 address_book.contacts.push(contact)