Ruby Ruby Objects and Classes Ruby Objects and Classes Creating and Instantiating a Class

Jan Oberreiter
Jan Oberreiter
69,585 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
69,585 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
69,585 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