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

Benjamin Miller
Benjamin Miller
4,344 Points

Instantiate an instance of the Name class and assign it to the variable name. This must come after the definition of the

?

Benjamin Miller
Benjamin Miller
4,344 Points

my code is: class Name def first_name "First" end

def last_name "Last" end end

4 Answers

You're supposed to instantiate a new instance of the class Name. Here's how you do so:

# Here's our class, Animal.

class Animal
    def eat
        puts "Ate 1000 calories of food!"
    end
end

# Here's how you should instantiate the Animal class:
# Over here i'm instanciating Animal and assigning it to a variable called jack_the_dog.
jack_the_dog = Animal.new

And, if you still aren't familiar with instantiating, you can always re-watch this video: https://teamtreehouse.com/library/ruby-objects-and-classes/ruby-objects-and-classes/instantiation

Good luck! ~Alex

Josh Salyer
Josh Salyer
7,265 Points

To instantiate a new instance of a class, you need to use the .new class method. For example:

class Contact
# Instance methods go here
end

# Instantiate a new instance and assign it to a variable
contact = Contact.new
Nickolas Fuentes
Nickolas Fuentes
14,016 Points

I was trying to create my own variable instead of using "name"

class Name
  def first_name
    "First"
  end

  def last_name
    "Last"
  end
end

name = Name.new