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 trialJames Mlambo
6,425 Pointswhere am I going wrong here
Create a to_s method for Name that returns the first_name and last_name separated by a space.
2 Answers
Salman Akram
Courses Plus Student 40,065 PointsHi James,
Here's to_s method solution.
def to_s
"#{first_name} #{last_name}"
end
Hope that helps.
Tiru Otilia
2,274 Pointsclass Name
attr_reader :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
first_name + ' ' + last_name
end
def to_s
full_name
end
end
James Mlambo
6,425 PointsJames Mlambo
6,425 Pointsthank you Salman
Salman Akram
Courses Plus Student 40,065 PointsSalman Akram
Courses Plus Student 40,065 PointsGreat. Just note that we encourage you to select best answer option to let other members know solutions available to the question. :)