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

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Someone explain to me why my full_name method doesn't work?

class Person
 attr_accessor :name, :job, :middle, :last

  def initialize(name, job)
    @name = name
    @job = job
  end
end

def full_name
    quote = ""
    quote += name
    if !middle.nil?
        quote += middle
        quote += last
    end
        quote += name
        quote += " "
        quote += last
end



ally = Person.new("Ally","Retail")
ally.name + " " + ally.job
ally.middle = "lawrence"
ally.last = "Cuccurullo"
ally.full_name

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

You have last_name outside the class. It needs to be inside to be an instance method instead of just a function. It also looks like the function is adding the pieces more than once.

class Person
 attr_accessor :name, :job, :middle, :last

  def initialize(name, job)
    @name = name
    @job = job
  end

  def full_name
      quote = ""
      quote += name
      if !middle.nil?
          quote += " " + middle
      end
      quote += " " + last
  end
end