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 trialdrizzy drake
Courses Plus Student 2,469 PointsBelow the Name class, instantiate a new Name instance set to the variable name with any title you choose.
I don't really understand what i need to do i'm very new to ruby
class Name
def name(name)
@name = name
end
def first_name
"Metal"
end
def last_name
"Robot"
end
def initialize (title)
@title = title
end
end
6 Answers
Maciej Czuchnowski
36,441 PointsYou have to go outside the class (under the end
keyword) and create a new variable called name
which will contain the new instance of Name class object. You can pass anything you want as title in the parentheses. Watch minute 3:00 of the video closely. There, Jason is completing the line you need to pass the exercise :)
Kenny Moreno
3,406 PointsTreeHouse questions are very confusing they ask you things backward
MUZ140166 Fungai Zarura
11,539 PointsYou should write it this way class Name
def first_name "Metal" end
def last_name "Robot" end def initialize (title) @title = title end
end name = Name.new("Mrs.")
Heather Stone
5,784 PointsI guess I don't really understand the question... can anyone re-word it for me? I just tried your code and obviously it works, but I'm not sure why or what I'm trying to do.
Annie Scott
27,613 Pointsclass Name def initialize(title) @title = title end
def last_name "Robot" end end
name = Name.new("Mrs.")
Roxana Guinea
5,675 Pointsclass Name def first_name "First" end
def last_name "Last" end end
name = Name.new puts name.first_name puts name.last_name
Justin Laos
Courses Plus Student 4,021 PointsAt the bottom put:
name = Name.new("Mr")
make sure to put a string in the perams, I first put (Mr) not ("Mr")
Lorraine Hutter
4,415 PointsLorraine Hutter
4,415 PointsSo, in my case, I got it to work by going to the bottom of the existing code and putting:
name = Name.new("Ms.")
(But this one really drove me bonkers for some reason. I kept updating the existing code rather than going outside of it.)