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