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 Class Design Phone Number Class

Immo Struchholz
Immo Struchholz
10,515 Points

Weird output from printPhoneNumber method

This is the output I get from the printPhoneNumbers method:

Phone Numbers:
Kind: mobile, Number: 123456789
#<PhoneNumber:0x0055d1c17face0>
Kind: mobile, Number: 326136121
#<PhoneNumber:0x0055d1c17faba0>

What is going on here? It's the same method as in the video:

    def printPhoneNumbers
        puts "Phone Numbers:"
        phoneNumbers.each { |n| puts n }
    end

3 Answers

Yup. You're fine leaving the colon in there. Your method, technically, is fine as well. Looks like you may need to review your to_s method.

Try:

def to_s
  "#{kind}: #{number}"
end

I'd also recommend staying with convention in regards to your naming of methods. By that I mean, stick with snake_case as opposed to camelCase.

Immo Struchholz
Immo Struchholz
10,515 Points

Thank you! My to_s method looked like this:

def to_s
    puts "Kind: #{kind}, Number: #{number}"
end

Removed the puts and now it works just fine.
Why is snake_case preferred? I only have experience with JavaScript and learned to use camelCase there.

Hi Immo, try this:

def print_phone_numbers
  puts "Phone Numbers"
  phone_numbers.each { |phone_number| puts phone_number }
end
Immo Struchholz
Immo Struchholz
10,515 Points

Hi Chet, That's the exact same method as the one I wrote. Minus the colon after phone numbers. I tried it anyway, but it didn't work.

I'm not positive why, other than it is the accepted way to do it by most Ruby programmers. My supposition is that it has to do with readability. Possibly to help differentiate from classes, which have CamelCase for their name's.