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
PRO
William Li
Pro Student 26,794 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.