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

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