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 trial

Ruby Ruby Objects and Classes Variables and Methods Variables and Methods

drizzy drake
PLUS
drizzy drake
Courses Plus Student 2,469 Points

Below 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.rb
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
Maciej Czuchnowski
36,441 Points

You 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 :)

So, 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.)

Kenny Moreno
Kenny Moreno
3,406 Points

TreeHouse questions are very confusing they ask you things backward

You 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.")

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

class Name def initialize(title) @title = title end

def last_name "Robot" end end

name = Name.new("Mrs.")

class Name def first_name "First" end

def last_name "Last" end end

name = Name.new puts name.first_name puts name.last_name

At the bottom put:

name = Name.new("Mr")

make sure to put a string in the perams, I first put (Mr) not ("Mr")