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 trialAlestaire Caines
70 PointsI don't get what they want me to do.
It seems hard
class Name
def first_name
"Metal"
end
def last_name
"Robot"
end
end
2 Answers
Ethan Rivas
9,979 PointsHi Alestaire Caines! Ok, I'm not a master but I can help you.
The challenge say: In the initialize method of the Name class, set an instance variable called @title to the title argument.
Note: you will have to write the initialize method.
First of all you have the Name class:
class Name
def first_name
"Metal"
end
def last_name
"Robot"
end
end
- 1) You have to define the method initialize:
def initialize #Initialize method.
end
- 2) Set an instance variable called @title to the title argument
def initialize(title) #That's the initialize method with the title argument.
@title = title #This is the instance varible to the title argument.
end
After that (here comes the second part)
- 3) Below the Name class, instantiate a new Name instance set to the variable name with any title you choose.
name = Name.new("Mr.")
After that (here comes the third part).
- 4) Inside the Name class, create a method called title that returns the @title variable.
def title
@title
end
And the last part.
- 5) Call the title method on the name instance.
name.title
This are all the parts for the challenge, I you now understand it and if you need more help I'm here :p.
Eva Pradhan
6,907 PointsThanks lot it was very useful. have a great day!
Benjamin Miller
4,344 PointsBenjamin Miller
4,344 Pointswhere do I put the name.title in the code?