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

Then when we create an instance of the object:

nick = "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.