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 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

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")