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 Ruby Objects and Classes Creating and Instantiating a Class

I would appreciate any help so much, I am stuck on this question for hours now and cannot move on.

the question is: Call the puts method with the name variable's first_name method as an argument ... and there are three more questions following ... I would appreciate any help gratefully ... kind regards, Jan.

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

  def title # Task 3
    @title
  end

  def name.first_name
    "Metal"
  end

  def last_name
    "Robot"
  end
end

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

3 Answers

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

You're making changes to the Name class, and you actually don't need to. You just need to create an instance of Name and call some methods on it.

Here's the challenge, solved up through Task 2. See if you can figure out the solution to Task 3 on your own.

class Name
  def first_name
    "First"
  end

  def last_name
    "Last"
  end
end

name = Name.new
puts name.first_name

Thank you Jay ... I will try as soon as I get to it, I just have too many other things to do at the moment ... but I will try figuring it out as soon as I find the time ... thank you ... regards, Jan.

I did Ruby again, from the very beginning on and now I cannot even understand, why I didn't understand this ... thank you a lot ... regards, Jan.

Here is the answer for number 3. puts name.last_name