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 Build an Address Book in Ruby Class Design Contact Class: Part 2

Initialize Method on the Contact Class?

This may be something Jason goes over in a later video, but why don't we create an initialize method to assign variables to the Contact object when we create it?

Something along the lines of this:

def initialize( first, middle, last)
  @first_name = first
  @middle_name = middle
  @last_name = last
end

Then when we create an instance of the object:

nick = Contact.new( "Nick", "A", "Pettit")
Mateo Sossah
Mateo Sossah
6,598 Points

Hey Michael, Did you end up getting an answer for that question somehow? I am wondering the same thing... Thanks

1 Answer

if you haven't already figured it out. The initialize method is optional but it is useful when you are going over a program and it is easier to give values to the variables.