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 Build an Address Book in Ruby Class Design Write a Method

Create a method called full_name that returns a string of the first_name and last_name attributes separated by a space.

Not sure where I am going wrong? :

def full_name puts "#{first_name} += "" += #{last_name}" end

end

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi Megan McMullin

> Create a method called full_name that returns a string of the first_name and last_name attributes separated by a space.

The problem here is that puts keyword in Ruby is for String output only, it doesn't return any value, but this challenge asks you to return the new String by combing first_name and last_name.

You may use the return keyword instead of the puts keyword for return statement in Ruby

  def full_name
    return "#{first_name} #{last_name}"
  end

Alternatively, Ruby allows you to omit the return keyword, the last line in the method body becomes the return statement by default.

  def full_name
    "#{first_name} #{last_name}"
  end

Make sense? reply if you have further question, happy coding.