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

Miles Smith
Miles Smith
2,688 Points

Build an Address Book

Hello Treehouse Community, i must not be understanding the question what is wrong with my code? Based off the question the class AddressBook is already created so all i would need to do is set address_book = AddressBook.new in a initialize method, but i guess not.

address_book.rb
contact = Contact.new
contact.first_name = "My"
contact.last_name = "Name"
def initialize
  address_book = Addressbook.new
end

1 Answer

Seth Reece
Seth Reece
32,867 Points

You don't need an initialize method. Just assign the address_book variable to a new AddressBook. The initialize method is part of a class to define default values.

e.g.

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

address_book = AddressBook.new
Miles Smith
Miles Smith
2,688 Points

When i do that exactly with nothing else except "address_book = Addressbook.new" i get this error "NameError: uninitialized constant Addressbook"

Seth Reece
Seth Reece
32,867 Points

oops, typo on my part. AddressBook.new. I'll change my code for future references.