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 Write a Method

Anna Shalaginova
Anna Shalaginova
3,160 Points

Full_name method not returning first_name and last_name

I am not sure where the error in the code is.

contact.rb
class Name
  attr_reader :first_name, :last_name

  def initialize(first_name, last_name)
    @first_name = first_name
    @last_name = last_name
  end

  def full_name
    @first_name + " " + @last_name
  end
end

2 Answers

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,723 Points

I honestly think it is something wrong with the testing in the challenge, since your code produces the correct result.

Shaun Dixon
Shaun Dixon
10,944 Points

It looks like you may have changed the name of the class as when I load the challenge the code looks like this:

class Contact
  attr_reader :first_name, :last_name

  def initialize(first_name, last_name)
    @first_name = first_name
    @last_name = last_name
  end


end

So the test is probably looking at the code with the original class name "Contact" . The method you have created to return the first name and last name is perfect and with this code below I pass the challenge.

class Contact
  attr_reader :first_name, :last_name

  def initialize(first_name, last_name)
    @first_name = first_name
    @last_name = last_name
  end

  def full_name
    @first_name + " " + @last_name
  end

end