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

Michelle Button
Michelle Button
1,520 Points

In the initialize method of the Name class, set an instance variable called @title to the title argument. Note: you will

I'm pretty lost on this one. I've tried everything. The code below is my last effort. Given the code that already appears on the screen, I find this question confusing.

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

def last_name "Robot" end end name = Name.new puts name.title

class.rb
class Name
  def initialize (title, first_name)
    @title = title
  end

  def last_name
    "Robot"
  end
end
name = Name.new
puts name.title

2 Answers

Hi Michelle,

You're pretty much there with all of that. The code should look something like:

class Name
  def initialize(title) # Task 1
    @title = title
  end

  def title # Task 3
    @title
  end

  def first_name
    "Metal"
  end

  def last_name
    "Robot"
  end
end

name = Name.new("Title") # Task 2
name.title # Task 4

I hope that helps.

Steve.

Michelle Button
Michelle Button
1,520 Points

Hey Steve,

Thank you so much! I was getting pretty frustrated with that task. I hope you enjoy the rest of your weekend!

No problem! :-)