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

Jan Oberreiter
Jan Oberreiter
77,985 Points

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
Jan Oberreiter
Jan Oberreiter
77,985 Points

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.

Jan Oberreiter
Jan Oberreiter
77,985 Points

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