Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Objects and Classes Variables and Methods Methods

Code Review Help

I don't understand what I'm doing wrong here.

name.rb
class Name
  attr_accessor :first_name, :last_name, :full_name

  def initialize(first_name, last_name, full_name)
    @first_name = first_name
    @last_name = last_name
    @full_name = first_name + " " + last_name
  end

end

bridget = Name.new("Bridget", "Jones", "Bridget Jones")
puts bridget.full_name
Sandra Hogan
Sandra Hogan
8,656 Points

I think what you want to do is initialize only the first_name and last_name, then create another method within the Name class called full_name where you concatenate @first_name and @last_name

Cody Kaup
Cody Kaup
14,407 Points

It's not the lack of a full_name method within the Name class because that's taken care of with the line regarding attr_accessor (which creates the getter and setter methods). This code worked perfectly fine for me. Would you be able to provide any error messages that you're getting?

Another note, adding full_name as an argument to initialize doesn't really make sense since you're just using first_name and last_name to set that property. I would remove that from the line creating the initialize method and when creating the class object. Something like this:

... def initialize(first_name, last_name) ... bridget = Name.new("Bridget", "Jones")