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

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,437 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")