Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Build an Address Book in Ruby!
You have completed Build an Address Book in Ruby!
Preview
The first part of our address book application that we'll address is creating a class to store our contacts. Unsurprisingly, we're calling this the Contact class!
Code Samples
class Contact
attr_writer :first_name, :middle_name, :last_name
def first_name
@first_name
end
def middle_name
@middle_name
end
def last_name
@last_name
end
def full_name
full_name = first_name
if !@middle_name.nil?
full_name += " "
full_name += middle_name
end
full_name += ' '
full_name += last_name
full_name
end
end
jason = Contact.new
jason.first_name = "Jason"
jason.last_name = "Seifer"
puts jason.full_name
nick = Contact.new
nick.first_name = "Nick"
nick.middle_name = "A"
nick.last_name = "Pettit"
puts nick.full_name
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
We're going to be building a command
line program that will let someone
0:00
put in the names and
information of all of their contacts.
0:02
Then, we'll add in the ability to go
through, and search these contacts.
0:06
We're going to create our own classes for
0:11
each different part of
the address book program.
0:13
This will encompass the address book
itself, contacts, and their information.
0:16
What we're doing is
abstracting away the logic
0:21
of these different parts of
the program into their own classes.
0:24
This is a good example of
object oriented programming.
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up