Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Ruby Objects and Classes Variables and Methods Variables and Methods

I don't get what they want me to do.

It seems hard

class.rb
class Name
  def first_name
    "Metal"
  end

  def last_name
    "Robot"
  end
end

2 Answers

Ethan Rivas
Ethan Rivas
9,979 Points

Hi 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.

Benjamin Miller
Benjamin Miller
4,344 Points

where do I put the name.title in the code?

Eva Pradhan
Eva Pradhan
6,907 Points

Thanks lot it was very useful. have a great day!