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

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