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,861 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,861 Points

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