Ruby Build an Address Book in Ruby Class Design Write a Method

Anna Shalaginova
Anna Shalaginova
2,101 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 46,095 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,943 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