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 trialJasmine Frantz
8,299 PointsI have the code exactly the same as Jason but mine prints out differently
I have the code exactly the same as Jason but mine prints out all the contact details before printing out contat_list, while Jason's video prints out only contact_list. Why is that? His video output does not seem right to me. I think my output is correct.
This question is in regard to
https://teamtreehouse.com/library/build-an-address-book-in-ruby/class-design/address-book-class
Build an address book in Ruby / Address book class
Jasmine Frantz
8,299 Pointsrequire "./acontact"
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
jasmine = Contact.new jasmine.first_name = "Jasmine" jasmine.last_name = "Frantz" jasmine.add_phone_number("Home", "123-456-789") jasmine.add_phone_number("Work", "432-123-456") jasmine.add_address("Home", "22 Siesta ct", "", "Sarasota", "FL", "34239")
address_book.contacts.push(jasmine)
address_book.print_contact_list
Ken jones
5,394 PointsHave you checked your contact.rb file to see if you are still printing the details out at the bottom of the page like he did to test if the instance methods were working?
If you are those commands will automatically run when you require the Contact class in your AddressBook class.
2 Answers
Ben Flores
17,074 PointsAs Ken Jones mentioned, you might be printing on another one of your files. In my case, My address.rb had a few put statements, which were affecting the outcome of this one.
Also! For future reference, use the Markdown Cheatsheet when including code! Makes it easier to read :)
Joshua Paulson
37,085 PointsWatch all Jason's videos at half speed. He's an amazing teacher but tends to type very quickly. Just slow down the video and you'll get it.
Matt Nickele
468 PointsMatt Nickele
468 Pointscan you post your code?