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

Sydney Cohen
Sydney Cohen
2,909 Points

Not sure what to do here: Instantiate an instance of the Name class and assign it to the variable name. This must come a

thanks for helping

name.rb
class Name  
  def first_name
    "First"
  end

  def last_name
    "Last"
  end
end

def name(name) 
  @name = name
end

3 Answers

Kevin Mulhern
Kevin Mulhern
20,374 Points

You need to create a new instance of the Name class. like this:

name = Name.new("kevin")
Sydney Cohen
Sydney Cohen
2,909 Points

Thanks Kelvin.. i got confused with the wording !!

Hi Sydney,

You need to put instance of variable "name" AFTER we have Name class, I know it is a bit trick. What we do is to add name instance in the end of the line below.

class Name
  def first_name
    "First"
  end

  def last_name
    "Last"
  end
end

name = Name.new
puts name

Good Example again at 2:43, you can idea of code samples under teacher's note.

This is what worked for me:

class Name
  def first_name
    "First"
  end

  def last_name
    "Last"
  end
end
# everything after this line is my attempt
name = Name.new