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 trialMiles Smith
2,688 PointsBuild 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.
contact = Contact.new
contact.first_name = "My"
contact.last_name = "Name"
def initialize
address_book = Addressbook.new
end
1 Answer
Seth Reece
32,867 PointsYou 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
2,688 PointsMiles Smith
2,688 PointsWhen i do that exactly with nothing else except "address_book = Addressbook.new" i get this error "NameError: uninitialized constant Addressbook"
Seth Reece
32,867 PointsSeth Reece
32,867 Pointsoops, typo on my part. AddressBook.new. I'll change my code for future references.